0% found this document useful (0 votes)
3 views2 pages

Arduino Button LED Control Code

This document contains an Arduino sketch that controls two buttons and two LEDs. When BUTTON1 is pressed, LED1 turns on, and when BUTTON2 is pressed, LED2 turns off. The setup function initializes the pins, and the loop function continuously checks the button states to control the LEDs accordingly.

Uploaded by

michelle
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Arduino Button LED Control Code

This document contains an Arduino sketch that controls two buttons and two LEDs. When BUTTON1 is pressed, LED1 turns on, and when BUTTON2 is pressed, LED2 turns off. The setup function initializes the pins, and the loop function continuously checks the button states to control the LEDs accordingly.

Uploaded by

michelle
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

const int BUTTON1 = 2;

const int BUTTON2 = 4;


const int LED1 = 8;
const int LED2 = 12;
int BUTTONstate1 = 0;
int BUTTONstate2 = 0;

void setup()
{
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}

void loop()
{
BUTTONstate1 = digitalRead(BUTTON1);
if (BUTTONstate1 == HIGH)
{
digitalWrite(LED1, HIGH);
}
else{
digitalWrite(LED1, LOW);
}
BUTTONstate2 = digitalRead(BUTTON2);
if (BUTTONstate2 == HIGH)
{
digitalWrite(LED2, LOW);
}
else{
digitalWrite(LED2, HIGH);
}
}

You might also like