Hello guys. So... i have 3 buttons and 5 (+4 more, at the end...) leds. What i want to do is to make a remote controll. Basicaly 1 button is for reset or jump (i will tell you what jump means), the other 2 are used to connect to either TV, DVD, RADIO or CD using 00 01 10 11 combinations. After it connects to one of the devices, i can choose either PROGRAMS or VOLUME using 10 and 01 combinations. After i choose programs/volume, i must use the buttons to Increase/Decrease volume, and move to the next/previous program using 00 01 10 11 combinations. The jump button will be used to exit these modes:
Ex: you connected to the TV, selected Programs, moved to the 31st program and you want to increase volume: you press JUMP and you get to the point where you select Program or Volume. But you can also press JUMP again, and you get to the connection phase (where the led blinks).
The graph is this one. I made only for the RADIO but its the same for the rest of them. Hope it
s easier to understand it now.
How i want to do the program:
First: i have 1 led that blinks untill one of the DEVICES combination is pressed (00 01 10 11). After it connects, the first led stays ON and also the LED of the DEVICE turns on. After that, you choose Programs or Volume and turn on 4 more leds (P+ P- V+ or V-). If i press JUMP, the last led must turn off...
I get problems registering the 00 combination...
this is my program so far (i did not add the last 4 leds for p+ p- v+ v-, first i want to make it connect to the devices, and be able to select program or volume)
const int b1 = 2; //button 1
const int b2 = 3; //button 2
const int ledPin = 8; //Connectivty led (which blinks first and then stays turned on)
const int ledTV = 9; //led TV
const int ledDVD = 10; //led DVD
const int ledCD = 11; //led CD
const int ledRAD = 12; //led RAD
int bState1 = 0; //state button 1
int bState2 = 0; //state button 2
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(b1, INPUT);
pinMode(b2, INPUT);
pinMode(ledTV, OUTPUT);
pinMode(ledDVD, OUTPUT);
pinMode(ledCD, OUTPUT);
pinMode(ledRAD, OUTPUT);
Serial.begin(9600);
}
int devicec = 6;
int revert = 0;
int connection = 0;
void loop()
{
bState1 = digitalRead(b1);
bState2 = digitalRead(b2);
if(bState1 == HIGH && bState2 == HIGH)
connection = 1;
if(connection == 1)
{
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500); //this should be the part where it blinks untill it`s connected
devicec=d();
switch (devicec) //where will it connect?
{
case 0:
digitalWrite(ledTV, HIGH);
digitalWrite(ledPin, HIGH);
connection=0;
break;
case 1:
digitalWrite(ledDVD, HIGH);
digitalWrite(ledPin, HIGH);
connection=0;
break;
case 2:
digitalWrite(ledCD, HIGH);
digitalWrite(ledPin, HIGH);
connection=0;
break;
case 3:
digitalWrite(ledRAD, HIGH);
digitalWrite(ledPin, HIGH);
connection=0;
break;
}
}
}
int d()
{
int state11 = 0;
int state22 = 0;
state11 = digitalRead(b1);
state22 = digitalRead(b2);
int nr = state11 + 2*state22;
return nr;
}
Thanks very much!