Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
project:arduino-kickstarter-105 [14.01.2013 15:56] – Externe Bearbeitung 127.0.0.1 | project:arduino-kickstarter-105 [20.11.2013 21:27] (aktuell) – paalsteek | ||
---|---|---|---|
Zeile 17: | Zeile 17: | ||
const int buttonPin = 2; // the number of the pushbutton pin | const int buttonPin = 2; // the number of the pushbutton pin | ||
const int ledPin = 13; // the number of the LED pin | const int ledPin = 13; // the number of the LED pin | ||
+ | | ||
// Variables will change: | // Variables will change: | ||
int ledState = HIGH; // the current state of the output pin | int ledState = HIGH; // the current state of the output pin | ||
int buttonState; | int buttonState; | ||
int lastButtonState = LOW; // the previous reading from the input pin | int lastButtonState = LOW; // the previous reading from the input pin | ||
+ | | ||
// the following variables are long's because the time, measured in miliseconds, | // the following variables are long's because the time, measured in miliseconds, | ||
// will quickly become a bigger number than can be stored in an int. | // will quickly become a bigger number than can be stored in an int. | ||
long lastDebounceTime = 0; // the last time the output pin was toggled | long lastDebounceTime = 0; // the last time the output pin was toggled | ||
long debounceDelay = 50; // the debounce time; increase if the output flickers | long debounceDelay = 50; // the debounce time; increase if the output flickers | ||
+ | | ||
void setup() { | void setup() { | ||
pinMode(buttonPin, | pinMode(buttonPin, | ||
pinMode(ledPin, | pinMode(ledPin, | ||
} | } | ||
+ | | ||
void loop() { | void loop() { | ||
// read the state of the switch into a local variable: | // read the state of the switch into a local variable: | ||
int reading = digitalRead(buttonPin); | int reading = digitalRead(buttonPin); | ||
+ | | ||
// check to see if you just pressed the button | // check to see if you just pressed the button | ||
// (i.e. the input went from LOW to HIGH), | // (i.e. the input went from LOW to HIGH), | ||
// long enough since the last press to ignore any noise: | // long enough since the last press to ignore any noise: | ||
+ | | ||
// If the switch changed, due to noise or pressing: | // If the switch changed, due to noise or pressing: | ||
if (reading != lastButtonState) { | if (reading != lastButtonState) { | ||
Zeile 55: | Zeile 55: | ||
// set the LED using the state of the button: | // set the LED using the state of the button: | ||
digitalWrite(ledPin, | digitalWrite(ledPin, | ||
+ | | ||
// save the reading. | // save the reading. | ||
// it'll be the lastButtonState: | // it'll be the lastButtonState: |