Engduino v1.0
Files | Functions
Driver for the Engduino Button

This is the driver code for the button on the Engduino. More...

Files

file  EngduinoButton.cpp
 

Engduino Button driver.


file  EngduinoButton.h
 

Engduino Button driver.


Functions

 ISR (INT6_vect)
 ISR for INT.6 on the ATMega32U4.
 EngduinoButtonClass::EngduinoButtonClass ()
 Constructor.
void EngduinoButtonClass::begin (long debounceDelay=DEBOUNCE_DELAY)
 begin function - must be called before using other functions
void EngduinoButtonClass::end ()
 end function - switch off the button
bool EngduinoButtonClass::isPressed ()
 Check to see if the button is pressed.
void EngduinoButtonClass::waitUntilPressed ()
 Wait until the button is pressed.
void EngduinoButtonClass::waitUntilReleased ()
 Wait until the button is released.
bool EngduinoButtonClass::wasPressed ()
 Check to see if the button was pressed since our last check.
bool EngduinoButtonClass::wasReleased ()
 Check to see if the button was released since our last check.
void EngduinoButtonClass::reset ()
 Reset the wasPressed/wasReleased state.

Detailed Description

This is the driver code for the button on the Engduino.

This uses an ISR to debounce the button - it uses edges rather than the value of the digital pin.

The debounce time can be set in the begin routine, but defaults to the DEBOUNCE_DELAY value defined in the header.


Function Documentation

void EngduinoButtonClass::begin ( long  debounceDelay = DEBOUNCE_DELAY)

begin function - must be called before using other functions

This function enables the button. It can be called with a parameter that represents the debounce delay, but this defaults to a sensible value if it is not provided.

Definition at line 45 of file EngduinoButton.cpp.

void EngduinoButtonClass::end ( )

end function - switch off the button

Switch off the interrupt and reset state.

Definition at line 87 of file EngduinoButton.cpp.

EngduinoButtonClass::EngduinoButtonClass ( )

Constructor.

C++ constructor for this class. Empty.

Definition at line 32 of file EngduinoButton.cpp.

bool EngduinoButtonClass::isPressed ( )

Check to see if the button is pressed.

Check to see if the button is pressed. If it is not pressed, it is, by definition, released.

Definition at line 106 of file EngduinoButton.cpp.

ISR ( INT6_vect  )

ISR for INT.6 on the ATMega32U4.

This is connected to the button.

This ISR is set to go off on either edge, but we change which edge depending on whether we last saw a falling edge or a rising edge. This seems overkill, but trying to implement this ISR to react to a change of any description doesn't work well, because we can't tell which direction the change is in. Given we have an edge, set the state of the button and whether it was pressed or released, but only if the switch isn't bouncing. We determine whether it is bouncing by looking at how long it's been stable for; if this is long enough, then we regard this as being the first edge (button not bouncing) and change state. If it is not, we simply record the current time as the time of the last change.

Definition at line 231 of file EngduinoButton.cpp.

void EngduinoButtonClass::reset ( )

Reset the wasPressed/wasReleased state.

This function resets the wasPressed/wasReleased state to false - it can be used to start a period of looking for a button press, ignoring what happened before reset was called. Note, however, that calling wasPressed or wasReleased also resets the appropriate part of the state.

Definition at line 207 of file EngduinoButton.cpp.

void EngduinoButtonClass::waitUntilPressed ( )

Wait until the button is pressed.

Blocking call.

Just loops indefinitely, polling the button state until the button is pressed. The event we wait for is the button going down. If the button is currently pressed, we wait for it to be released and then wait for it to be pressed again

Definition at line 124 of file EngduinoButton.cpp.

void EngduinoButtonClass::waitUntilReleased ( )

Wait until the button is released.

Blocking call.

Just loops indefinitely, polling the button state until the button is released. The event we wait for is the button going up. If the button is currently released, we wait for it to be pressed and then wait for it to be released again

Definition at line 145 of file EngduinoButton.cpp.

bool EngduinoButtonClass::wasPressed ( )

Check to see if the button was pressed since our last check.

Returns:
Whether or not is has been pressed since we last checked.

This function checks to see if the button has been pressed in some intervening period when we were not checking it actively. On each check we return a boolean that shows whether the button has been pressed, and we reset the state so one can look for a new button press at some later point.

Definition at line 169 of file EngduinoButton.cpp.

bool EngduinoButtonClass::wasReleased ( )

Check to see if the button was released since our last check.

Returns:
Whether or not is has been released since we last checked.

This function checks to see if the button has been released in some intervening period when we were not checking it actively. On each check we return a boolean that shows whether the button has been released, and we reset the state so one can look for a new button release at some later point.

Definition at line 189 of file EngduinoButton.cpp.