ok so i took mike cooks original code for neopixels without delay
ive managed to get it to work up to the point of having the fade effect, red, green, blue static lights, cycling back around to fade, however when adding a case to have solid white, it just stays on red and you have to press the button twice and it will go back to fade (so basically, the colour isnt changing from red to white)
also if i add a case for all off, so set to 0, 0, 0, 0, it jams up on that button press.
helibob i had noticed that. once corrected that part functioned properly, but i also realised that the code above was designed for several rings of neopixels,
heres the newest version, if one of you guys would be so kind as to highlight where its going wrong for white and off, i'd be grateful, its almost there, just those 2 cases to get funcitoning.
// StrandTest from AdaFruit implemented as a state machine
// pattern change by push button
// By Mike Cook Jan 2016
#define PINforControl 7 // pin connected to the small NeoPixels strip
#define NUMPIXELS1 1 // number of LEDs on strip
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS1, PINforControl, NEO_GRB + NEO_KHZ800);
unsigned long patternInterval = 20 ; // time between steps in the pattern
unsigned long lastUpdate = 0 ; // for millis() when last update occoured
unsigned long intervals [] = { 20, 20, 50, 100 } ; // speed for each pattern
const byte button = 2; // pin to connect button switch to between pin and ground
void setup() {
strip.begin(); // This initializes the NeoPixel library.
wipe(); // wipes the LED buffers
pinMode(button, INPUT_PULLUP); // change pattern button
}
void loop() {
static int pattern = 0, lastReading;
int reading = digitalRead(button);
if(lastReading == HIGH && reading == LOW){
pattern++ ; // change pattern number
if(pattern > 4) pattern = 0; // wrap round if too big
patternInterval = intervals[pattern]; // set speed for this pattern
wipe(); // clear out the buffer
delay(50); // debounce delay
}
lastReading = reading; // save for next time
if(millis() - lastUpdate > patternInterval) updatePattern(pattern);
}
void updatePattern(int pat){ // call the pattern currently being created
switch(pat) {
case 0:
rainbow();
break;
case 1:
colorWipe(strip.Color(0, 0, 255)); // blue
break;
case 2:
colorWipe(strip.Color(0, 255, 0)); // green
break;
case 3:
colorWipe(strip.Color(255, 0, 0)); // red
break;
case 4:
colorWipe(strip.Color(175, 175, 175)); // white
break;
case 5:
colorWipe(strip.Color(0, 0, 0)); // off
break;
}
}
void rainbow() { // modified from Adafruit example to make it a state machine
static uint16_t j=0;
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
j++;
if(j >= 256) j=0;
lastUpdate = millis(); // time for next change to the display
}
void colorWipe(uint32_t c) { // modified from Adafruit example to make it a state machine
static int i =0;
strip.setPixelColor(i, c);
strip.show();
i++;
if(i >= strip.numPixels()){
i = 0;
wipe(); // blank out strip
}
lastUpdate = millis(); // time for next change to the display
}
void wipe(){ // clear all LEDs
for(int i=0;i<strip.numPixels();i++){
strip.setPixelColor(i, strip.Color(0,0,0));
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
not too fussed about using "colorwipe" instead of setcolor