Hello everyone.
I have an idea about using a remote controller i had laying around to control a bunch of LED's.
The receiver is a tdl-9921. I did my homework and found the way to connect it to my Arduino Leonardo using the RCSwitch library.
At the moment i can make the arduino run a loop for each key i press in the remote. My goal is to interrupt that loop when a new key is pressed on the remote.
I read about interrupts on arduino, but since the voltage on the data pin of the receiver does not change when a key is pressed i need to go in another direction. Hope you can help me find it.
This is the code i have at the moment, modified from a RCSwitch example:
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int led = 13;
void setup() {
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #3 on Leonardo
}
void loop() {
if (mySwitch.available()) {
if ( mySwitch.getReceivedValue() == 5592512) {
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
} else
if ( mySwitch.getReceivedValue() == 5592368) {
for (int Count2=0; Count2 < 200; Count2++){
digitalWrite(led,HIGH);
delay(100);
digitalWrite(led,LOW);
delay(50);
}
} else
if ( mySwitch.getReceivedValue() == 5592332) {
//another type of blink goes here
} else
if ( mySwitch.getReceivedValue() == 5592323) {
//and another one goes here
}
mySwitch.resetAvailable();
}
At this moment the code detects one key press, does whatever i put inside the if code and then stops, waiting for another key press.
For simplicity, lets just say that i want to be able to interrupt the blinking in the second if whenever i press another key in the controller.
Thanks.