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 revision
Previous revision
Next revisionBoth sides next revision
arduino:arduino_crash_course:basic_interaction [2012/11/05 22:13] mithatarduino:arduino_crash_course:basic_interaction [2012/11/12 04:36] mithat
Line 17: Line 17:
 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, Arduino will turn an LED on. If it is not pressed, it will turn the LED off.
  
-==== Using external pulldown resistors ====+==== With external pulldown resistors ====
 The following example requires **pulldown resistors** on the input switch. The following example requires **pulldown resistors** on the input switch.
  
Line 100: Line 100:
 </file> </file>
  
-==== Using internal pullups ====+==== With internal pullup resistors ====
  
 Using extenal resistors as part of switch state detection is so common that the microchip that is at the heart of the Arduino has built-in pullup resistors that can be turned on manually. Internal pullup resistors can be enabled with: Using extenal resistors as part of switch state detection is so common that the microchip that is at the heart of the Arduino has built-in pullup resistors that can be turned on manually. Internal pullup resistors can be enabled with:
Line 132: Line 132:
  
   // set LED state accordingly   // set LED state accordingly
-  // note the inverted logic+  // becasue we are using pullup resistors, the logic is inverted; 
 +  // in other words, pressed produces LOW, un-pressed produces HIGH.
   if (buttonState == LOW)        // if the button is pushed   if (buttonState == LOW)        // if the button is pushed
     digitalWrite(ledPin, HIGH);  // turn the LED on     digitalWrite(ledPin, HIGH);  // turn the LED on
Line 158: Line 159:
  
 void loop() { void loop() {
-  buttonState = !digitalRead(pushButtonPin);  // read the input pin +  buttonState = digitalRead(pushButtonPin);  // read the input pin 
-  digitalWrite(ledPin, buttonState);              // turn the LED on or off+  
 +  // set LED state accordingly 
 +  // becasue we are using pullup resistors, the logic is inverted; 
 +  // in other words, pressed produces LOW, un-pressed produces HIGH. 
 +  digitalWrite(ledPin, !buttonState);        // turn the LED on or off
 } }
 </file> </file>
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