I am a newbie and was able to modify this code to partial work. Need suggestions to add additional patterns, and after last pattern, start over.
// include the library code:
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal.h>
// Setup Constant for button
const int button1Pin = 1; // pushbutton 1 pin
int buttonPin = 3; // momentary push button on pin 0
int oldButtonVal = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define PIN 5
// 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(10, 5, NEO_GRB + NEO_KHZ800);
int nPatterns = 3;
int lightPattern = 1;
// the setup routine runs once when you press reset:
void setup() {
strip.begin();
strip.show(); // initialize all pixels to 'off'
// initialize the BUTTON pin as an input
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("LED,LCD,&Button");
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH); // button pin is HIGH, so it drops to 0 if pressed
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
// Pattern 1 - Red light, all LEDs in the strip are red
void pattern1() {
lcd.setCursor(0, 1);
lcd.print("Red Lights");
colorWipe(strip.Color(255, 0, 0), 50); // Blue
}
// Pattern 2 - Blue light, all LEDs in the strip are blue
void pattern2() {
lcd.setCursor(0, 1);
lcd.print("Blue Lights");
colorWipe(strip.Color(0, 0, 255), 50);
}
// Pattern 3 - Rainbow light, all LEDs in the strip are different colors
void pattern3() {
lcd.setCursor(0, 1);
lcd.print("Rainbow Lights");
rainbow(20);
rainbowCycle(20);
}
// the loop routine runs over and over again forever;
void loop() {
int buttonVal = digitalRead(buttonPin);
if (buttonVal == LOW && oldButtonVal == HIGH) {// button has just been pressed
lightPattern = lightPattern + 1;
}
if (lightPattern > nPatterns) lightPattern = 1;
oldButtonVal = buttonVal;
switch(lightPattern) {
case 1:
pattern1();
break;
case 2:
pattern2();
break;
case 3:
pattern3();
break;
}
}