mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
First integration of the Arduino code in Processing 5503: PreProcessor and Compiler have been integrated with changes to the Sketch.
Compilation still has problems (Thread error on success, and can't handle non-pde files in a sketch). Modified the Mac OS X make.sh to copy the hardware, avr tools, and example over. Removing some of the antlr stuff. Disabling the Commander (command-line execution) for now. Added Library, LibraryManager, and Target. Added support for prefixed preferences (e.g. for boards and programmers).
This commit is contained in:
52
build/shared/examples/Digital/Debounce/Debounce.pde
Normal file
52
build/shared/examples/Digital/Debounce/Debounce.pde
Normal file
@ -0,0 +1,52 @@
|
||||
/* Debounce
|
||||
*
|
||||
* Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||
* press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||
* a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||
* noise).
|
||||
*
|
||||
* David A. Mellis
|
||||
* 21 November 2006
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
|
||||
int inPin = 7; // the number of the input pin
|
||||
int outPin = 13; // the number of the output pin
|
||||
|
||||
int state = HIGH; // the current state of the output pin
|
||||
int reading; // the current reading from the input pin
|
||||
int previous = LOW; // the previous reading from the input pin
|
||||
|
||||
// the follow variables are long's because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long time = 0; // the last time the output pin was toggled
|
||||
long debounce = 200; // the debounce time, increase if the output flickers
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(inPin, INPUT);
|
||||
pinMode(outPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
reading = digitalRead(inPin);
|
||||
|
||||
// if we just pressed the button (i.e. the input went from LOW to HIGH),
|
||||
// and we've waited long enough since the last press to ignore any noise...
|
||||
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
|
||||
// ... invert the output
|
||||
if (state == HIGH)
|
||||
state = LOW;
|
||||
else
|
||||
state = HIGH;
|
||||
|
||||
// ... and remember when the last button press was
|
||||
time = millis();
|
||||
}
|
||||
|
||||
digitalWrite(outPin, state);
|
||||
|
||||
previous = reading;
|
||||
}
|
Reference in New Issue
Block a user