User Tools

Site Tools


arduino:arduino_crash_course:basic_interaction

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
arduino:arduino_crash_course:basic_interaction [2012/11/12 04:36] mithatarduino:arduino_crash_course:basic_interaction [2015/02/13 22:27] mithat
Line 15: Line 15:
 ===== Switch-controlled LED ===== ===== Switch-controlled LED =====
  
-The following examples use polling to determine the state of a switch. If the switch is pressed, Arduino will turn an LED on. If it is not pressed, it will turn the LED off.+The following examples use polling to determine the state of a switch. If the switch is pressed, the Arduino will turn an LED on. If it is not pressed, it will turn the LED off.
  
 ==== With external pulldown resistors ==== ==== With external pulldown resistors ====
Line 39: Line 39:
   buttonState = digitalRead(pushButtonPin);  // read the input pin   buttonState = digitalRead(pushButtonPin);  // read the input pin
  
-    // set LED state accordingly+  // set LED state accordingly
   if (buttonState == HIGH)       // if the button is pushed   if (buttonState == HIGH)       // if the button is pushed
     digitalWrite(ledPin, HIGH);  // turn the LED on     digitalWrite(ledPin, HIGH);  // turn the LED on
Line 45: Line 45:
     digitalWrite(ledPin, LOW);   // turn the LED off     digitalWrite(ledPin, LOW);   // turn the LED off
  
-  //delay(1);        // delay in between reads for stability (?)+  //delay(1);        // delay between reads for stability (?? I don't remember why this got in here.)
 } }
 </file> </file>
  
-Notice the use of an ''if-else'' statement. The ''if-else'' statement is an example of **flow control**.+Notice the use of an ''if-else'' statement. The ''if-else'' statement is an example of **control flow**.
  
 A more compact version of the above that eliminates the if-else statement: A more compact version of the above that eliminates the if-else statement:
arduino/arduino_crash_course/basic_interaction.txt · Last modified: 2017/12/06 01:05 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki