Event booking for offline workshop on Arduino Alvik started. Seats: 30 only. Click here to Book Now!
The most interesting thing in this code uses the default “running” keyword of Arduino. It is a library function in Arduino, also known as Boolean variable.
The Code
/* * Toggling the LED with a switch * Vidyasagar Academy Akola * www.vsa.edu.in */ // The most intersting thing in this code uses
the default "running" keyword of Arduino int LED=3; int Switch=1; // push-to-on switch connected between pin-1 & ground bool running=false; void setup() { pinMode(LED,OUTPUT); pinMode(Switch,INPUT); digitalWrite(Switch,HIGH); // turn on pullup resistor } void loop() { if(digitalRead(Switch)==LOW) { // switch is pressed - pullup keeps pin high normally delay(100); // delay to debounce switch running=!running; // toggle running variable digitalWrite(LED,running); // LED is ON } }