I have 4 adafruit 25 pixel strands connected to an Arduino Uno. Previously I had a button with a pull-up resistor connected to pin2 as an interrupt, but as I originally thought that might be related to my issue I've removed everything for now (including the button and related hardware connected to the Arduino).
So I've completely stripped down my code to make it as simple as possible and I'm still getting this very strange issue. Basically, the program correctly sets the 100 pixels one at a time to an off-white color. For the first 100 iterations of loop(), mode is 0 and the animation runs fine. Once it hits the end of the strand, mode changes to 30 and I can't seem to figure out why.
The output being as you would expect:
0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/30/... etc
The idea being that each press of the button should increment mode and cause the strand to switch to the next pattern. It should be able to continue animating indefinitely while performing other tasks on each frame. For now I just have removed all but one pattern, but the purpose of the switch is to allow many patterns.
#include "SPI.h"
#include "Adafruit_WS2801.h"
int dataPin = 3; // Yellow wire on Adafruit Pixels
int clockPin = 5; // Green wire on Adafruit Pixels
Adafruit_WS2801 strip = Adafruit_WS2801(100, dataPin, clockPin);
int const pixels = 100;
int a[pixels]; //brightness
int r[pixels];
int g[pixels];
int b[pixels];
int mode = 0;
int currentLED = 0;
void setup() {
strip.begin();
Serial.begin(9600);
clear();
strip.show();
}
void loop() {
Serial.print(mode);
Serial.print("/");
// drawing
switch (mode) {
case 0:
colorWipe(255, 220, 255, 30);
break;
}
// update the entire strand
for (int i; i < pixels; i++) {
strip.setPixelColor(i, Color(r[i] * (a[i] / 255) , g[i] * (a[i] / 255) , b[i] * (a[i] / 255 )));
}
// show the changes
strip.show();
}
void clear() {
for (int i = 0; i < pixels; i++) {
r[i] = 0;
b[i] = 0;
g[i] = 0;
a[i] = 0;
}
}
// fill the dots one after the other with said color
void colorWipe(byte myA, byte myR, byte myG, byte myB) {
a[currentLED] = myA;
r[currentLED] = myR;
g[currentLED] = myG;
b[currentLED] = myB;
currentLED++;
if (currentLED > pixels) {
currentLED = 0;
}
}
/* Helper functions */
// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}
I'm completely at a loss what else I can try. There is no longer any code that modifies the value of mode so I don't even see where to start troubleshooting.
Thanks for any suggestions