Hi,
I am a bit new in the Arduino programming world and it's my first time asking for help. I'm probably missing something very simple.
The project:
By using the RadioHead library and the FastLed library, I try to make an led lantern that change every time it received a string via RF433hz.
A RF433hz transmitter is sending a 6 character string like "ZONE A" and then on the receiver (the led lantern) I'm reiceiving it and then send a chase to the LEDs on the "ZONE A" condition ( or anything the string can be ).
So far everything works great in a range of 20' without antenna. Exactly what I wanted to prevent overlap.
The problem :
I want it to keep chasing the last received cue over and over again until a different string is received. So when the lantern goes in a dead zone it's not black.
My diagnosis:
As I use bool for cues, I don't get why it's stopping from chasing. Even if any conditions is unfulfilled the last "true" bool should stay right ?
In my code after each chase the RF ask fonction is resend, so I suspect that; because the string is empty on a dead zone, nothing happen and the bool are all false...
I know that I am near the solution I just might miss something very simple.
Thank you.
The code ( using Arduino Nano v3 ) :
//RF 433 Rx Libs
#include <RH_ASK.h>
#include <SPI.h>
//data pin to D11
RH_ASK rf_driver;
String str_out;
//FastLed Libs
#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 100
CRGB leds[NUM_LEDS];
//cue variable
bool cueA = false;
bool cueB = false;
bool cueC = false;
void setup() {
//RF 433 setup
rf_driver.init();
Serial.begin(115200);
//FastLed setup
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
//RF 433 loop
//Size of string message
uint8_t buf[6];
uint8_t buflen = sizeof(buf);
if (rf_driver.recv(buf, &buflen)) {
str_out = String((char*)buf);
str_out.remove(6, 10);
Serial.println(str_out);
//CUE A
if (str_out == "ZONE A") {
cueA = true;
cueB = false;
cueC = false;
//FastLed CUE A
if (cueA == true) {
for (int i = 0; i <= 99; i++) {
leds[i] = CRGB ( 255, 0, 0);
FastLED.show();
delay(20);
}
for (int i = 0; i <= 99; i++) {
leds[i] = CRGB ( 0, 0, 0);
FastLED.show();
delay(20);
}
for (int i = 0; i <= 99; i++) {
leds[i] = CRGB ( 255, 15, 0);
FastLED.show();
delay(20);
}
for (int i = 0; i <= 99; i++) {
leds[i] = CRGB ( 0, 0, 0);
FastLED.show();
delay(20);
}
}
}
//CUE B
if (str_out == "ZONE B") {
cueA = false;
cueB = true;
cueC = false;
//FastLed CUE B
if (cueB == true) {
for (int i = 0; i <= 99; i++) {
leds[i] = CRGB ( 0, 0, 25);
FastLED.show();
delay(20);
}
for (int i = 99; i >= 0; i--) {
leds[i] = CRGB ( 255, 0, 80);
FastLED.show();
delay(20);
}
}
}
//CUE C
if (str_out == "ZONE C") {
cueA = false;
cueB = false;
cueC = true;
//FastLed CUE C
if (cueC == true) {
for (int i = 0; i <= 99; i++) {
leds[i] = CRGB ( 0, 0, 25);
FastLED.show();
delay(20);
}
}
}
}
}