Victory-Noah Moussoki
Published

Push Button LED

In this lab is to use a push button to turn on and off an LED light bulb.

BeginnerFull instructions provided2,237
Push Button LED

Things used in this project

Hardware components

MSP-EXP432P401R SimpleLink MSP432 LaunchPad
Texas Instruments MSP-EXP432P401R SimpleLink MSP432 LaunchPad
×1
Push Button
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Code

Untitled file

C/C++
//Pushbutton switch demo: LED is connected to digital pin 8 and Pushbutton is connected to digital pin 12. 
//The LED glows when the button is pressed.
 
char inputButtonState;
 
void setup()   
{                
  pinMode(8, OUTPUT);        // Initialize Arduino Digital Pins 8 as output for connecting LED
  pinMode(12,INPUT);         // Initialize Arduino Digital Pins 12 as input for connecting Pushbutton
}
 
 
void loop()                     
{
  inputButtonState = digitalRead(12); //Read the Pushbutton state.
 
  if (inputButtonState == HIGH) 
  {     
    digitalWrite(8, HIGH);  //Switch on LED
  } 
  else 
  {
    digitalWrite(8, LOW);   //Switch off LED
  }
 
}

Credits

Victory-Noah Moussoki

Victory-Noah Moussoki

3 projects • 6 followers
18 year old future Automotive Mechanical Engineer. Math and science. In my free time i like to swim, play basketball, baseball, and football.
Thanks to Trey German.

Comments