5
Button::Button( int pin )
8
_last_state( digitalRead( pin )? true : false ),
9
_last_millis( millis() )
14
void Button::add_event_at( int duration, int event_id )
16
_press_events[ duration ] = event_id;
26
int millis = ::millis();
28
// get state and check for change
29
bool state = digitalRead( _pin )? true : false;
30
if( state != _last_state )
32
// if the button has become unpressed
35
// check through events to see if it had been pressed long enough
37
int duration = millis - _last_millis;
38
for( std::map< int, int >::iterator i = _press_events.begin();
39
i != _press_events.end(); i++ )
41
if( duration > i->first )
42
_event_id = i->second;
50
_last_millis = millis;
57
int Button::get_triggered_event()