As I said in my last post, the first thing I wanted to do with the Gemma and NeoPixels was to get the NeoPixels to blink different colours in sequence and to use the switch to start the sequence and stop it (after the lights had completed their sequence). To try and accomplish this the circuit was set up as follows:
To help me with the code I went to the Learn section of the Adafruit website (https://learn.adafruit.com) and looked at other projects that had been done with the Gemma and Flora. I found the Gemma introduction (https://learn.adafruit.com/introducing-gemma) and the close encounters hat (https://learn.adafruit.com/close-encounters-hat) guides very useful for this project.
// Easter bonnet - Hats off challenge 2014 // Light sequence plus switch // The following were used as guides for the code: // Close Encouters Hat - Adafruit // Introdution to Gemma - Adafruit #include <Adafruit_NeoPixel.h> int SWITCH = 0; #define LED 1 //led attached to pin 1 //Parameter 1 = number of pixels in strip //Parameter 2 = pin number (most are valid) //Parameter 3 = pixel type flags, add together as needed: //NEO_RGB Pixels are wired for RGB bitstream //NEO_GRB Pixels are wired for GRB bitstream //NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) //NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, LED, NEO_GRB + NEO_KHZ800); //i.e.(4 NeoPixels, Pin 1, NEO_GRB + NEO_800KHz) void setup() { strip.begin(); strip.show(); pinMode(SWITCH, INPUT); digitalWrite(SWITCH, HIGH); } void loop() { if(! digitalRead(SWITCH)){ //if the switch is pressed strip.setBrightness(85); strip.setPixelColor(0, 255,255,255); //white strip.setPixelColor(1, 255,255,0); //yellow strip.setPixelColor(2, 255,128,0); //orange strip.setPixelColor(3, 255,0,0); //red strip.show(); delay(1000); strip.setPixelColor(0, 255,255,0); //yellow strip.setPixelColor(1, 255,128,0); //orange strip.setPixelColor(2, 255,0,0); //red strip.setPixelColor(3, 255,0,255); //pink strip.show(); delay(1000); strip.setPixelColor(0, 255,128,0); //orange strip.setPixelColor(1, 255,0,0); //red strip.setPixelColor(2, 255,0,255); //pink strip.setPixelColor(3, 0,0,255); //blue strip.show(); delay(1000); strip.setPixelColor(0, 255,0,0); //red strip.setPixelColor(1, 255,0,255); //pink strip.setPixelColor(2, 0,0,255); //blue strip.setPixelColor(3, 128,255,0); //green strip.show(); delay(1000); strip.setPixelColor(0, 255,0,255); //pink strip.setPixelColor(1, 0,0,255); //blue strip.setPixelColor(2, 128,255,0); //green strip.setPixelColor(3, 255,255,255); //white strip.show(); delay(1000); strip.setPixelColor(0, 0,0,255); //blue strip.setPixelColor(1, 128,255,0); //green strip.setPixelColor(2, 255,255,255); //white strip.setPixelColor(3, 255,255,0); //yellow strip.show(); delay(1000); strip.setPixelColor(0, 128,255,0); //green strip.setPixelColor(1, 255,255,255); //white strip.setPixelColor(2, 255,255,0); //yellow strip.setPixelColor(3, 255,128,0); //orange strip.show(); delay(1000); strip.setPixelColor(0, 0,0,0); //clear strip.setPixelColor(1, 0,0,0); strip.setPixelColor(2, 0,0,0); strip.setPixelColor(3, 0,0,0); strip.show(); delay(1); // when stop pressed, the sequence continues to the end and finishes on the final colour. // To turn it "off" clear added to the list so it stops on this. // The short delay hides the clear stage from the loop } else { digitalWrite(SWITCH,HIGH); } }
The idea is that each NeoPixel will run through a sequence of colours, including white, yellow, orange, red, pink, blue and green when the button/switch is pressed. The first NeoPixel (0) would run the sequence in this order. The second (1) would start from yellow and carry on in the same sequence ending on white. The third (2) would start from orange and so on. Each colour is lit for approximately 1 second before changing to the next colour. The sequence then runs in a loop until the switch is pushed again. Although at this point, the sequence doesn’t stop dead, but carries on until the last colour in the sequence is lit and then goes off. In the code, you will notice that I also put a clear section in. This was added because when stopping the sequence the NeoPixel would remain lit the last colour. By putting the delay to 1 (a thousandth of the other colours) the clear is unnoticeable in the sequence.
So that is the light sequence I would like to use in my hat. It will probably change as the hat evolves. Currently I’m waiting for the bonnet/hat (due to arrive the middle of September), which will act as the base of my design. Hopefully, when this arrives I can make more (and better) judgement calls on the final aesthetics of my Easter bonnet.