I'm having trouble implementing a simple colour changer using 4 Neopixel 1/4 ring and Nano. It seems to work through the first 2 colours but then, what looks like a power drop, the current colour remains permanent albeit dimmed. Im also having issues with my cct but I've run the Strand Test example from Adaruit and everything seems fine. My cct issue is that I can't upload when I have the Neopixel ring attached.
Any help with my code will be appreciated.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
const byte numReadings = 15;
const byte sensitivity = 52;
const int fadeTime = 500;
const int waitTime = 2000;
const int pixels = strip.numPixels();
const byte ARRAY_SIZE = 13;
const byte colours[] = {140, 5, 9,
195, 69, 0,
171, 126, 0,
255, 216, 1,
4, 92, 18,
0, 147, 174,
23, 114, 205,
7, 40, 155,
30, 38, 113,
16, 20, 83,
96, 18, 102,
127, 0, 22,
255, 148, 131,
255, 255, 255
};
byte colR = 0;
byte colG = 0;
byte colB = 0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// Serial.begin(9600);
}
void loop() {
delay(waitTime);
colourCycle();
}
void colourCycle() {
for (int j = 0; j < sizeof(colours); j = j + 3) {
//show colour
for (int k = 0; k < fadeTime; k++) {
uint32_t col = getColour(k, fadeTime, colR, colG, colB, colours[j], colours[j+1], colours[j+2]);
for (int i = 0; i < pixels; i++) {
strip.setPixelColor(i, col);
}
strip.show();
}
if (j < ARRAY_SIZE - 3) {
colR = colours[j];
colG = colours[j + 1];
colB = colours[j + 2];
} else {
colR = colours[0];
colG = colours[1];
colB = colours[2];
}
delay(waitTime);
}
}
uint32_t getColour(int i, int f, byte cR, byte cG, byte cB, byte cRN, byte cGN, byte cBN) {
byte r = 0;
byte g = 0;
byte b = 0;
float rL = cRN - cR;
float gL = cGN - cG;
float bL = cBN - cB;
r = byte(cR + rL / f * i);
g = byte(cG + gL / f * i);
b = byte(cB + bL / f * i);
// Serial.print(r);
// Serial.print(" ");
// Serial.print(g);
// Serial.print(" ");
// Serial.println(b);
return strip.Color(r, g, b);
}