Statistics
| Revision:

root / Ports / examples / button_demo / button_demo.pde

History | View | Annotate | Download (1.3 KB)

1
//>>> The latest version of this code can be found at https://github.com/jcw/ !!
2
3
// Show how the BlinkPlug's buttonCheck function works
4
// 2010-08-23 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php
5
// $Id: button_demo.pde 7763 2011-12-11 01:28:16Z jcw $
6
7
#include <Ports.h>
8
#include <RF12.h> // needed to avoid a linker error :(
9
10
BlinkPlug blink (1);
11
MilliTimer everySecond;
12
13
void setup () {
14
    Serial.begin(57600);
15
    Serial.println("\n[button_demo]");
16
}
17
18
void loop () {
19
    byte event = blink.buttonCheck();
20
    switch (event) {
21
        
22
    case BlinkPlug::ON1:
23
        Serial.println("  Button 1 pressed"); 
24
        break;
25
    
26
    case BlinkPlug::OFF1:
27
        Serial.println("  Button 1 released"); 
28
        break;
29
    
30
    case BlinkPlug::ON2:
31
        Serial.println("  Button 2 pressed"); 
32
        break;
33
    
34
    case BlinkPlug::OFF2:
35
        Serial.println("  Button 2 released"); 
36
        break;
37
    
38
    default:
39
        // report these other events only once a second
40
        if (everySecond.poll(1000)) {
41
            switch (event) {
42
                case BlinkPlug::SOME_ON:
43
                    Serial.println("SOME button is currently pressed");
44
                    break;
45
                case BlinkPlug::ALL_OFF:
46
                    Serial.println("NO buttons are currently pressed");
47
                    break;
48
            }
49
        }
50
    }
51
}