Devices & Components
Arduino Uno Rev3
Resistor 1k ohm
LED (generic)
Jumper wires (generic)
Tactile Switch, Top Actuated
Breadboard (generic)
Software & Tools
Arduino IDE
Project description
Code
Two LEDs and Two Push Buttons with opposite effect
arduino
Two LEDs and Two Push Buttons with opposite effect
1const int BUTTON1 = 2; 2const int BUTTON2 = 4; 3const int LED1 = 8; 4const int LED2 = 12; 5int BUTTONstate1 = 0; 6int BUTTONstate2 = 0; 7 8void setup() 9{ 10 pinMode(BUTTON1, INPUT); 11 pinMode(BUTTON2, INPUT); 12 pinMode(LED1, OUTPUT); 13 pinMode(LED2, OUTPUT); 14} 15 16void loop() 17{ 18 BUTTONstate1 = digitalRead(BUTTON1); 19 if (BUTTONstate1 == HIGH) 20 { 21 digitalWrite(LED1, HIGH); 22 } 23 else{ 24 digitalWrite(LED1, LOW); 25 } 26 BUTTONstate2 = digitalRead(BUTTON2); 27 if (BUTTONstate2 == HIGH) 28 { 29 digitalWrite(LED2, LOW); 30 } 31 else{ 32 digitalWrite(LED2, HIGH); 33 } 34} 35
Downloadable files
Breadboard Diagram
Make connections as shown in the figure.
Breadboard Diagram

Comments
Only logged in users can leave comments