variables in arduino programming

Simplest code of Toggling the LED using Arduino

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  } }

Share on your network!
Dattaraj Vidyasagar
Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

Leave a Reply

Your email address will not be published. Required fields are marked *