#10Beginner
Led Burning with Button (On Off)
4.8(98)
156 completed

A toggle project that changes the state of the LED (on/off) with each button press. Teaches state variable and debounce logic.
Video
Circuit Diagram

Source Code
1int ledState = 0;
2
3void setup() {
4 pinMode(13, INPUT);
5 pinMode(7, OUTPUT);
6}
7
8void loop() {
9 if (digitalRead(13) == 1) {
10 ledState = !ledState;
11 digitalWrite(7, ledState);
12 delay(300);
13 }
14}