I have a strip of leds cut into pairs; each pair is in its own lantern, and I want the lanterns to alternate whatever I put through them.
I am using FastLED library. I have posted what I have come up with. It seems to work in the console; the arrays generated are right(or seem to be)' even[] = {0,1,4,5,8,9...}; odd[] = {2,3,6,7,10,11...}' but lantern #1 does not work as the rest do for some reason.
lantern #1 = leds[even[0]] and leds[even[1]] should both display Eval color but leds[even[1]] is displaying Oval color.
the other lanterns display properly
lantern #2 = leds[odd[0]] and leds[odd[1]] displays Oval color.
lantern #3 = leds[even[2]] and leds[even[3]] displays Eval color.
lantern #4 = leds[odd[2]] and leds[odd[3]] displays Oval color.
etc...
#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 3
#define POT_PIN A0
int potValue;
int even[NUM_LEDS]; //{0,1,4,5,8,9...}
int odd[NUM_LEDS]; //{2,3,6,7,10,11...}
int Epos = 0; //count position for adding lanterns to even/odd arrays
int Opos = 0;
int lantern = 1; // 1 and 2 switch back and forth between lanterns
int pos = 0; // count 2 leds per lantern
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
for (int i=0;i<NUM_LEDS;i++){ //go through leds
if (pos == 2){
pos = 0;
if (lantern == 1){
lantern = 2;
}
else if (lantern == 2){
lantern = 1;
}
}
switch (lantern){
case 1: // even lantern
even[Epos] = i; // i = led on strip
Epos++;
pos++;
break;
case 2: // odd lantern
odd[Opos] = i; // i = led on strip
Opos++;
pos++;
break;
}
}
Serial.print("\n even: ");
for (int x=0;x<NUM_LEDS;x++){
Serial.print(even[x]);
}
Serial.print("\n odd: ");
for (int x=0;x<NUM_LEDS;x++){
Serial.print(odd[x]);
}
}
//////////////////////////////////////////////////////////////////////////
void split(){
potValue = analogRead(POT_PIN);
int Eval;
int Oval;
int Eval = potValue; //color value for even lanterns
int Oval = map(potValue,0,1023, 10,500); //offset color value for odd lanterns
for (int i=0;i<NUM_LEDS;i++){
leds[even[i]] = CHSV(Eval,255,255);
delay(1);
leds[odd[i]] = CHSV(Oval,255,255);
}
FastLED.show();
}
///////////////////////////////////////////////////////////////////////////
void loop() {
split();
}
I am pretty new to Arduino.have I done something wrong? Is this an efficient way to go about this?