25/06/2015
3
*/
4
5
int
buttonPin = 2; // button pin ‐‐ Digital 2
6
int
relayPin = 3; // relay pin ‐‐ Digital 3
7
int
relayState = HIGH;
8
int
buttonState;
9
int
lastButtonState = LOW;
10
long
lastDebounceTime = 0;
11
long
debounceDelay = 50;
12
13
void
setup() {
14
pinMode(buttonPin, INPUT);
15
pinMode(relayPin, OUTPUT);
16
17
digitalWrite(relayPin, relayState);
18
}
19
void
loop() {
20
// read the state of the switch into a local variable:
21
int
reading = digitalRead(buttonPin);
22
23
// check to see if you just pressed the button
24
// (i.e. the input went from LOW to HIGH), and you've waited
25
// long enough since the last press to ignore any noise:
26
27
// If the switch changed, due to noise or pressing:
28
if
(reading != lastButtonState) {
29
lastDebounceTime = millis();
30
}
31
32
if
((millis() ‐ lastDebounceTime) > debounceDelay) {
33
// whatever the reading is at, it's been there for longer
34
// than the debounce delay, so take it as the actual current state:
35
36
// if the button state has changed:
37
if
(reading != buttonState) {
38
buttonState = reading;
39
40
// only toggle the Relay if the new button state is HIGH
41
if
(buttonState == HIGH) {
42
relayState = !relayState;
43
}
44
}
45
}
46
47
// set the relay:
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100
DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki
17/23
Need help?
Do you have a question about the DFR0100 and is the answer not in the manual?