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
Next revisionBoth sides next revision
arduino:basic_interaction [2012/09/13 05:44] – [Switch controlled LED] mithatarduino:basic_interaction [2012/09/13 05:47] mithat
Line 9: Line 9:
 Of the two, polling is probably easier to get started with. Following is a simple example of using polling. Of the two, polling is probably easier to get started with. Following is a simple example of using polling.
  
-===== Switch controlled LED =====+===== Switch-controlled LED =====
  
-This example uses 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 off.+This example uses 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.
  
 <file c LightSwitch.ino> <file c LightSwitch.ino>
Line 20: Line 20:
  
 // connect the push button to digital pin 2 // connect the push button to digital pin 2
-int pushButton = 2;+int pushButtonPin = 2;
 // connect the LED to pin 13 // connect the LED to pin 13
 int ledPin = 13; int ledPin = 13;
  
 void setup() { void setup() {
-  pinMode(pushButton, INPUT);   // make the pushbutton's pin an input +  pinMode(pushButtonPin, INPUT);  // make the pushbutton's pin an input 
-  pinMode(ledPin, OUTPUT);      // make LED's pin an output+  pinMode(ledPin, OUTPUT);        // make LED's pin an output
 } }
  
 void loop() { void loop() {
-  int buttonState = digitalRead(pushButton);  // read the input pin+  int buttonState = digitalRead(pushButtonPin);  // read the input pin
  
   // set LED state accordingly   // set LED state accordingly
Line 53: Line 53:
  
 // connect the push button to digital pin 2 // connect the push button to digital pin 2
-int pushButton = 2;+int pushButtonPin = 2;
 // connect the LED to pin 13 // connect the LED to pin 13
 int ledPin = 13; int ledPin = 13;
  
 void setup() { void setup() {
-  pinMode(pushButton, INPUT);   // make the pushbutton's pin an input +  pinMode(pushButtonPin, INPUT);  // make the pushbutton's pin an input 
-  pinMode(ledPin, OUTPUT);      // make LED's pin an output+  pinMode(ledPin, OUTPUT);        // make LED's pin an output
 } }
  
 void loop() { void loop() {
-  int buttonState = digitalRead(pushButton);  // 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 78: Line 78:
  
 // connect the push button to digital pin 2 // connect the push button to digital pin 2
-int pushButton = 2;+int pushButtonPin = 2;
 // connect the LED to pin 13 // connect the LED to pin 13
 int ledPin = 13; int ledPin = 13;
  
 void setup() { void setup() {
-  pinMode(pushButton, INPUT);   // make the pushbutton's pin an input +  pinMode(pushButtonPin, INPUT);  // make the pushbutton's pin an input 
-  pinMode(ledPin, OUTPUT);      // make LED's pin an output+  pinMode(ledPin, OUTPUT);        // make LED's pin an output
 } }
  
 void loop() { void loop() {
-  digitalWrite(ledPin, digitalRead(pushButton));  // 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