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

Dr. Dattaraj Vidyasagar
Dr. Dattaraj Vidyasagar

M.S. Electronics & Telecomm. (Cleveland Institute of Electronics, Ohio), Associate Member (IETE, Kolkata), Panelist on Dr. Homi Bhabha Foundation, Google certified educator (Level-1), Mentor of Change (MoC-1619) Niti Ayog, Government of India, International Robotics Trainer, Veteran of Applied Electronics since 35+ years.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x