Identify bugs and resolve it to fulfill following objective. Interface 3 LEDs and 4 SWICHES with Arduino. Develop a program that by pressing 1st switch it will ON LED1, by pressing 2nd switch it ON LED2 and same for 3rd switch and LED3. By pressing 4th switch it will reset (OFF) all LEDs.

 



Here i am using online IDE Tinkercad . If you don't know what is tinkercad then refer my blog HERE or else you can use offline IDE also.

Code :-

const int LED1 = 7;

const int LED2 = 6;

const int LED3 = 5;

const int BUTTON1 = 2;

const int BUTTON2 = 3;

const int BUTTON3 = 0;

const int BUTTON4 = 1;

int Buttonmodel = 0;

int Buttonmode2 = 0;

int Buttonmode3 = 0;

int Buttonmode4 = 0;

void setup () {

// put your setup code here, to run once:

pinMode(LED1,OUTPUT);

pinMode(LED2, OUTPUT);

pinMode(LED3, OUTPUT);

pinMode(BUTTON1,INPUT);

pinMode(BUTTON2,INPUT);

pinMode(BUTTON3,INPUT);

pinMode(BUTTON4,INPUT);

}

void loop(){

//First LED interface

Buttonmode1 == digitalRead(BUTTONl);

if(Buttonmode1 = HIGH)

{

digitalWrite(LED1,HIGH);

}

//Second LED interface

Butonmode2 = digita1Read (BUTTON2);

if(Buttonmode2 = HIGH)

{

digitalWrite(LED2,HIGH);

 }

//Third LED interface

Buttonmode3 = digitalRead(BUTTON3);

if(Buttonmode3 = HIGH);

{

digitalWrite(LED3,HIGH);

}

//Fourth LED interface

Buttonmode4 = digitalRead(BUTTON4);

if(Buttonmode4 = HIGH)

{

digitalWrite(LED1,LOW);

digitalWrite(LED2,LOW);

digitalWrite(LED3,LOW);

}

}

Comments