//Press a button to turn on an LED light. Release the button to turn off the light.
void setup(){
pinMode(8,OUTPUT); //LED light
pinMode(6,INPUT_PULLUP); //Button
}
void loop(){
if(digitalRead(6)==LOW){ //If the button reading is LOW (the button is pressed)...
digitalWrite(8,HIGH); //turn on the LED light
}
else{
digitalWrite(8,LOW); //otherwise (if the button reading isn't LOW), turn off th
}
}
// (c) 2024 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
It looks like your computer isn't set up to code yet.
Success!
Compile errors:
Serial port monitor:
Input:
Walkthrough Video
Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!
Challenges
Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!