Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
KRIVANJADIYables
Published © GPL3+

Working with two LEDs and two PUSH BUTTONs

This project illustrates the use of two PUSH BUTTONS to operate two LEDs

BeginnerProtip81,496
Working with two LEDs and two PUSH BUTTONs

Things used in this project

Story

Read more

Schematics

Breadboard Diagram

Make connections as shown in the figure.

Code

Two LEDs and Two Push Buttons with opposite effect

Arduino
Two LEDs and Two Push Buttons with opposite effect
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);
  }
}

Credits

KRIVANJA
37 projects • 52 followers
www.krivanja.dev
Contact
DIYables
0 projects • 86 followers
I would like to invite you to join and add your projects to DIYables platform https://www.hackster.io/diyables
Contact

Comments

Please log in or sign up to comment.