Hello everyone!
I am a scale-modeller and want to enhance my next model a bit by adding lighting to it. I did that before with physical switches on the model without any Issues but this time around, I wanted the LEDs to be controlled by an IR-Remote.
To be very honest: most of my knowledge about Arduino comes from YouTube videos and copy-pasting stuff off the Internet.
Now to the project: I have managed to have constant-shining-LEDs turn on and off with the remote with no issues(will be utilized for interior lighting etc.). Since my Model is a rescue helicopter, it will need to have a beacon- and a strobe-light. I also know that using delay() does not work for my kind of project so I decided to use millis(). When I simply have the LEDs flashing at different rates and no IR-remote, It also works fine. Its also no problem when I introduce the IR-stuff to the code and only try to turn one of the two LEDs on, but as soon as I try to turn on the second LED, either the first or the second one is lit up constantly and nothing else happens. I´ve already looked through many forum entries here and elsewhere but cant seem to find an exact answer so I turn to this forum in hopes of finding a way to do what I plan to do.
Here is the code so far (note: this code only includes the blinking LEDs as of now since I tested the non-blinking LEDs already and want to approach the topic one at a time)
Thanks in advance!!
#include <IRremote.h>
int receiver = 11;
uint32_t Previous;
IRrecv irrecv(receiver);
decode_results results;
const int led1 = 8;
const long onDuration = 1201;
const long offDuration = 199;
int LEDstate1 = LOW;
const int led2 = 7;
const long onDuration2 = 1219;
const long offDuration2 = 167;
int LEDstate2 = LOW;
long rememberTime=0;
long rememberTime2=0;
void setup() {
pinMode(led1, OUTPUT);
digitalWrite(led1, LEDstate1);
pinMode(led2, OUTPUT);
digitalWrite(led2, LEDstate2);
Serial.begin (9600);
irrecv.enableIRIn();
}
void loop() {
{if (results.value==0xFFA25D){
if ( LEDstate1 == LOW )
{
if( (millis()-rememberTime) >= onDuration){
LEDstate1 = HIGH;
rememberTime=millis();
}
}
else
{
if( (millis()- rememberTime) >= offDuration){
LEDstate1 = LOW;
rememberTime = millis();
}
}
digitalWrite(led1, LEDstate1);
}
}
{if (results.value==0xFF629D){
if ( LEDstate2 == LOW )
{
if( (millis()-rememberTime2) >= onDuration2){
LEDstate2 = HIGH;
rememberTime2=millis();
}
}
else
{
if( (millis()- rememberTime2) >= offDuration2){
LEDstate2 = LOW;
rememberTime2 = millis();
}
}
digitalWrite(led2, LEDstate2);
}
}
if (irrecv.decode(&results)){
if (results.value==0xFFFFFFFF){
results.value=Previous;
}
Serial.println (results.value, HEX);
irrecv.resume();
}
}