Hi All,
I'm hoping someone on here may see what I'm doing wrong with my code. Basically I'm using a Pro Mini to light up a string of neopixels when a formatted string is sent over serial (e.g. #111333555777999AAABBB).
the 3 arrays will be full of 1024 values. If I try to lookup a value for any of the arrays, the arduino appears to crash with a constant or very fast flashing green led. Anyone see where I'm going wrong?
#include <Adafruit_NeoPixel.h>
#define NEOPIXEL_PIN 6
int numPixels = 1;
int curPixel = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
int r_colValues[1024] = {0,3,18,5,24,38,10,34,2,51,19,49,5,77,6,18,67,43,59,53,1,57,0,6,11,80,2,61,31,29,59,71,3,101,64,28,44,92,96,21,19,39,105,4,4,17,23,35,75,40,36};
int g_colValues[1024] = {0,13,20,15,24,14,8,4,23,16,55,8,75,15,92,65,31,20,51,18,48,42,86,6,3,58,77,28,43,77,87,53,103,38,29,69,47,48,40,89,71,52,0,48,136,69,52,2};
int b_colValues[1024] = {0,2,8,35,20,18,55,38,59,18,13,36,16,6,2,21,12,51,5,49,83,34,52,127,125,2,62,57,73,42,2,24,43,15,63,60,67,18,22,51,75,74,60,114,26,81,92,103};
void setup() {
Serial.begin(9600);
//Set the pixels white to begin with
strip.begin();
for(int j = 0; j < numPixels; j++)
{
strip.setPixelColor(j, 255,255,255);
}
strip.show();
}
void loop() {
int i = 0;
int inByte;
char power[2];
power[0] = 0;
//Run while the Serial port is recieving data
while(Serial.available() && i < 3)
{
inByte = Serial.read();
if(inByte == '#')
{
//Send colors to the neopixel string
strip.show();
Serial.println("Pixels Lit");
continue;
}
else
{
//Store the power to lookup
power[i++] = inByte;
}
}
//This is where the color codes are looked up and transmitted to the string
if(power[0] != 0)
{
int colPtr = strtol(power, NULL, 16);
strip.setPixelColor(curPixel++, r_colValues[colPtr], g_colValues[colPtr], b_colValues[colPtr]);
}
if(curPixel >= numPixels) curPixel = 0;
delay(1000);
}