Close

Hallo World (DIY extension)

A project log for Hacking a Fairphone

...or how to build an extension module, that can enhance your abilities with your phone.

kirschner-christophKirschner Christoph 02/19/2018 at 18:530 Comments

/*
 Name:		Hallo_World_DIY_Extension_FP2.ino
 Created:	07.01.2018 13:13:43
 Author:	Kirschner Christoph
*/

#include <Adafruit_NeoPixel.h>

int LEDs[8]{ 8,9,10,11,12,13,14,15 };

// Pin connected to the Neopixel 
#define PIN            17

// How many NeoPixels are attached 
#define NUMPIXELS      1

// Definition of the Neopixel
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
// Setting the pinmode of the GPIOs for the LEDs
	for (int i = 0; i < 8; i++) {
		pinMode(LEDs[i], OUTPUT);
}
// Starting the Neopixel
	pixels.begin();
	pinMode(17, OUTPUT);
}
void loop() {

// LEDs are blinking in a row 
	for (int i = 0; i < 8; i++) {
		digitalWrite(LEDs[i], HIGH);
		if (i > 0) {
			digitalWrite(LEDs[i - 1], LOW);
		}
		delay(50);
    }
	for (int i = 8; i >= 0; i--) {
		digitalWrite(LEDs[i], HIGH);
		digitalWrite(LEDs[i + 1], LOW);
		delay(50);
	}
	for (int i = 0; i<256; i++) {		
		// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
		pixels.setPixelColor(0, pixels.Color(0, i, 0)); // Moderately bright green color.
		pixels.show(); // This sends the updated pixel color to the hardware.
		delay(5); // Delay for a period of time (in milliseconds).
	}
	for (int i = 255; i>0; i--) {	
		// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
		pixels.setPixelColor(0, pixels.Color(0, i, 0)); // Moderately bright green color.
		pixels.show(); // This sends the updated pixel color to the hardware.
		delay(5); // Delay for a period of time (in milliseconds).
	}
	pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // Neopixel: off
	pixels.show(); // This sends the updated pixel color to the hardware.
}

Discussions