Hello everyone! My issue pertains to a persistence-of-vision LED stick project.
In it, I use a MATLAB script to turn an input image into an Arduino array, for ease of use.
My issue is that the Arduino is not selecting the correct value from my array, even with correct indexes.
The following is my code, with the red variable truncated due to posting requirements:
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN 2
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 28
CRGB leds[NUM_LEDS];
#define FRAMES_PER_SECOND 3
int count=0;
void setup() {
delay(1000); // 1 second delay for recovery
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
float batvolt = 5.0*(analogRead(A5)/1023.0)*(57.0/10.0);
if (batvolt > 6.4) {
FastLED.setMaxPowerInVoltsAndMilliamps( 5, 3000);
FastLED.setBrightness(25);
Serial.begin(9600);
Serial.print("battery power, voltage: ");
Serial.println( batvolt);
}
else if((batvolt <=6.4) && (batvolt > 5.0)) {
FastLED.setMaxPowerInVoltsAndMilliamps( 5, 400);
FastLED.setBrightness(25);
Serial.begin(115200);
Serial.print("LOW BATTERY: ");
Serial.println(batvolt);
lowbatterywarning();
}
else{
FastLED.setMaxPowerInVoltsAndMilliamps( 5, 400);
FastLED.setBrightness(25);
Serial.begin(115200);
Serial.print("USB power, voltage: ");
Serial.println(batvolt);
}
}
const PROGMEM byte red[][28]={
{ 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, 32, 67, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 64, 10, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0,124,255,255,255,255,255,255,255,255,255,255,255,255,255,250, 38, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0,123,255,255,255,255,255,255,255,255,255,255,255,255,255,247, 37, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0,124,255,255,255,255,255,255,255,255,255,255,255,255,255,250, 38, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 32, 69, 68, 68, 68, 66,153,255,255,230, 75, 67, 68, 68, 66, 10, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,113,255,255,220, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0,100,209,208,208,208,207,229,255,255,248,209,207,208,208,200, 30, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0,125,255,255,255,255,255,255,255,255,255,255,255,255,255,252, 38, 0, 0, 0, 0, 0, 0}};
void loop() {
for(int o=1;o<56 ;o++){
for(int k=1;k<NUM_LEDS ;k++){
leds[k].r=red[o][k];
//leds[k].g=grn[o][k];
//leds[k].b=blu[o][k];
leds[k].g=0;
leds[k].b=0;
Serial.print(o);
Serial.print(',');
Serial.print(k);
Serial.print(':');
Serial.print(red[o][k]);
Serial.print(',');
Serial.print(0);
Serial.print(',');
Serial.println(0);
FastLED.show();
FastLED.delay(1000/FRAMES_PER_SECOND);
}
FastLED.show();
FastLED.delay(10000/FRAMES_PER_SECOND);
}
count++;
if ( ((count % (FRAMES_PER_SECOND *60)) == 0)) {
lowbatterycheck();
}
}
void lowbatterycheck() {
float batvolt = 5.0*(analogRead(A5)/1023.0)*(57.0/10.0);
if ((batvolt <=6.4) && (batvolt > 5.0)){
lowbatterywarning();}
}
void lowbatterywarning() {
for(int k=0;k<5 ;k++) {
for( int i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(50,0,0);
}
FastLED.show();
FastLED.delay(1000/FRAMES_PER_SECOND);
for( int i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(0,0,0);}
FastLED.show();
FastLED.delay(1000/FRAMES_PER_SECOND);
}
while(1){};
}
The following is my serial output, with the indexes used listed, followed by the specified index in the array. However, if you use these indexes to manually lookup the values, they are quite different (specifically lookup 1,8). Any advice on how to fix this would be greatly appreciated!
USB power, voltage: 4.43
1,1:0,0,0
1,2:0,0,0
1,3:0,0,0
1,4:0,0,0
1,5:0,0,0
1,6:0,0,0
1,7:0,0,0
1,8:181,0,0
1,9:181,0,0
1,10:181,0,0
1,11:181,0,0
1,12:181,0,0
1,13:181,0,0
1,14:181,0,0
1,15:181,0,0
1,16:181,0,0
1,17:181,0,0
1,18:181,0,0
1,19:181,0,0
1,20:181,0,0
1,21:181,0,0
1,22:181,0,0
1,23:181,0,0
1,24:181,0,0
1,25:181,0,0
1,26:181,0,0
1,27:181,0,0
2,1:181,0,0
2,2:181,0,0
2,3:181,0,0
2,4:181,0,0
2,5:181,0,0
2,6:181,0,0
2,7:181,0,0
2,8:181,0,0
2,9:181,0,0
2,10:181,0,0
2,11:181,0,0
2,12:181,0,0
2,13:181,0,0
2,14:0,0,0
2,15:181,0,0
2,16:1,0,0
2,17:4,0,0
2,18:108,0,0
2,19:0,0,0
2,20:0,0,0
2,21:181,0,0
2,22:0,0,0
2,23:181,0,0
2,24:0,0,0
2,25:248,0,0
2,26:254,0,0
2,27:255,0,0
PS. my code compiles with no compiler related errors, just this main issue.