User Tools

Site Tools


arduino: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
Last revisionBoth sides next revision
arduino:basic_interaction [2012/09/14 00:45] mithatarduino:basic_interaction [2012/09/14 01:06] mithat
Line 14: Line 14:
  
 <WRAP center round important 60%> <WRAP center round important 60%>
-The following examples will need switches with pullups or internal pullups turned on with +The following examples will need switches with external pullups or internal pullups turned on via: 
  
 <code c> <code c>
Line 21: Line 21:
  
 I suspect internal pullups is the better way to go but possibly harder to explain. I suspect internal pullups is the better way to go but possibly harder to explain.
 +
 +Alternately, use external pulldowns and keep the logic uninverted.
 </WRAP> </WRAP>
  
Line 43: Line 45:
  
   // set LED state accordingly   // set LED state accordingly
-  if (buttonState == HIGH)        // 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 
-  else                            // otherwise +  else                           // otherwise 
-    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 in between reads for stability (?)
Line 72: Line 74:
 void loop() { void loop() {
   int buttonState = digitalRead(pushButtonPin);  // read the input pin   int buttonState = digitalRead(pushButtonPin);  // read the input pin
-  digitalWrite(ledPin, buttonState);          // turn the LED on or off+  digitalWrite(ledPin, !buttonState);          // turn the LED on or off
   //delay(1);        // delay in between reads for stability (?)   //delay(1);        // delay in between reads for stability (?)
 } }
Line 94: Line 96:
  
 void loop() { void loop() {
-  digitalWrite(ledPin, digitalRead(pushButtonPin));  // read the input pin and turn the LED on or off+  digitalWrite(ledPin, !digitalRead(pushButtonPin));  // read the input pin and turn the LED on or off
   //delay(1);        // delay in between reads for stability (?)   //delay(1);        // delay in between reads for stability (?)
 } }
 </file> </file>
arduino/basic_interaction.txt · Last modified: 2012/09/14 01:19 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki