Hello guys, I'm new into all of these and tried to control 3 LEDs with an IR remote control. I've managed to do that but i need to add another function to my circuit.
I want to remember my LED states when the power is off.
Found a few samples but couldn't understand them all. If someone can show it on my coding, it'd be highly appreciated.
I'm doing this for a small project which will be graded as a Visa in university. So don't blame me because of i'm asking a direct help.
After this is done only thing i'll need to do is to figure out how to make it work stand alone.
Thanks in advance.
/*
Microprocessors FIZ434E - Celal Ege Demir 090060127 - Onur Erbay 090090184
*/
#include <IRremote.h>
void ledleri_yak(int led_deger);
int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838
int led1 = 2;
int led2 = 4;
int led3 = 7;
int itsONled[] = {0,0,0,0};
/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1's if you want a certain
led to light when the board is powered */
#define code1 11535 // code received from button 2
#define code2 62569 // code received from button 3
#define code3 56187 // code received from button 4
#define code4 10947 // code received from button 1
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
if(itsONled[1] == 1) { // if first led is on then
digitalWrite(led1, LOW); // turn it off when button is pressed
itsONled[1] = 0; // and set its state as off
} else { // else if first led is off
digitalWrite(led1, HIGH); // turn it on when the button is pressed
itsONled[1] = 1; // and set its state as on
}
break;
case code2:
if(itsONled[2] == 1) {
digitalWrite(led2, LOW);
itsONled[2] = 0;
} else {
digitalWrite(led2, HIGH);
itsONled[2] = 1;
}
break;
case code3:
if(itsONled[3] == 1) {
digitalWrite(led3, LOW);
itsONled[3] = 0;
} else {
digitalWrite(led3, HIGH);
itsONled[3] = 1;
}
break;
case code4:
digitalWrite(led1, LOW);
itsONled[1] = 0;
digitalWrite(led2, LOW);
itsONled[2] = 0;
digitalWrite(led3, LOW);
itsONled[3] = 0;
}
Serial.println(value);
irrecv.resume();
}
}