const int ledPin=13;
const int ledPin2=12;
const int ledPin3=8;
const int buttonPin=2;
const int buttonPin2=3;
const int buttonPin3=7;
boolean lastButton=LOW;
boolean currentButton=LOW;
boolean ledOn=false;
boolean lastButton2=LOW;
boolean currentButton2=LOW;
boolean ledOn2=false;
boolean lastButton3=LOW;
boolean currentButton3=LOW;
boolean ledOn3=false;
int b3=0,b2=0,b1=0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(4, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin2, INPUT);
pinMode(ledPin3, OUTPUT);
pinMode(buttonPin3, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(14, OUTPUT);
//digitalWrite(14 , HIGH);
Serial.begin(9600);
}
boolean debounce(boolean last,int bp)
{
boolean current=digitalRead(bp);
if (last!=current)
{
current=digitalRead(bp);
}
return current;
}
void switchOffLED()
{
digitalWrite(5 , false);//a
digitalWrite(4 , false);//b
digitalWrite(14 , false);//c
digitalWrite(6 , false); //d
digitalWrite(9 , false); //e
digitalWrite(10 , false); //f
digitalWrite(11 , false);//g
}
void loop()
{
//Code for the first button from right to left
/*int bs=digitalRead(buttonPin);
Serial.println(bs);*/
//b1=b2=b3=0;
//b1=1;
currentButton=debounce(lastButton,buttonPin);
if (lastButton==LOW && currentButton==HIGH)
{
ledOn=!ledOn;
// Serial.println(ledOn);
//digitalWrite(ledPin, ledOn);
//digitalWrite(4 , ledOn);
// digitalWrite(2 , ledOn);
if (b1==0)
b1=1;
else
b1=0;
}
lastButton=currentButton;
digitalWrite(ledPin, ledOn);
//Code for the second button from right to left
currentButton2=debounce(lastButton2,buttonPin2);
if (lastButton2==LOW && currentButton2==HIGH)
{
ledOn2=!ledOn2;
if (b2==0)
b2=1;
else
b2=0;
}
lastButton2=currentButton2;
digitalWrite(ledPin2, ledOn2);
//Code for the third button from right to left
currentButton3=debounce(lastButton3,buttonPin3);
if (lastButton3==LOW && currentButton3==HIGH)
{
ledOn3=!ledOn3;
if(b3==0)
b3=1;
else
b3=0;
}
lastButton3=currentButton3;
digitalWrite(ledPin3, ledOn3);
if(b3==0 && b2==0 && b1==0) //0 Output
{
switchOffLED();
digitalWrite(5 , true);
digitalWrite(4 , true);
digitalWrite(14 , true);
digitalWrite(6 , true);
digitalWrite(9 , true);
digitalWrite(10 , true);
}
else if(b3==0 && b2==0 && b1==1) //1 Output
{
switchOffLED();
digitalWrite(4 , true);
digitalWrite(14 , true);
}
if(b3==0 && b2==1 && b1==0) //2 Output
{
switchOffLED();
digitalWrite(5, true);
digitalWrite(4 , true);
digitalWrite(11 , true);
digitalWrite(9 , true);
digitalWrite(6 , true);
}
if (b3==0 && b2==1 && b1==1)
{
switchOffLED();
digitalWrite(5, true);
digitalWrite(4, true);
digitalWrite(14, true);
digitalWrite(6, true);
digitalWrite(11, true);
}
if (b3==1 && b2==0 && b1==0)
{
switchOffLED();
digitalWrite(4, true);
digitalWrite(14, true);
digitalWrite(10, true);
digitalWrite(11, true);
}
if (b3==1 && b2==0 && b1==1)
{
switchOffLED();
digitalWrite(5, true);
digitalWrite(14, true);
digitalWrite(6, true);
digitalWrite(10, true);
digitalWrite(11, true);
}
if (b3==1 && b2==1 && b1==0)
{
switchOffLED();
digitalWrite(14, true);
digitalWrite(6, true);
digitalWrite(9, true);
digitalWrite(10, true);
digitalWrite(11, true);
}
if (b3==1 && b2==1 && b1==1)
{
switchOffLED();
digitalWrite(5, true);
digitalWrite(4, true);
digitalWrite(14, true);
}
}