|
mthread 0.5
|
Handler for a switch input. More...
#include <mthread.h>
Public Types | |
| enum | Type { pull_up_internal, pull_up, pull_down } |
Types of switches. More... | |
Public Member Functions | |
| SwitchInput (int pin, unsigned long debounce=DEFAULT_DEBOUNCE, Type type=pull_up_internal) | |
| Constructor. | |
| virtual | ~SwitchInput () |
| Destructor. | |
| bool | is_closed () |
| Checks to see if the switch is closed. | |
| bool | is_open () |
| Checks to see if the switch is open. | |
| virtual void | on_close () |
| Called when the switch closes. | |
| virtual void | on_open () |
| Called when the switch opens. | |
| unsigned long | time_closed () |
| Checks the length of time for which the switch has been closed. | |
| unsigned long | time_open () |
| Checks the length of time for which the switch has been open. | |
Protected Member Functions | |
| bool | loop () |
| Main loop. | |
Private Attributes | |
| unsigned long | debounce |
| The debounce time (in milliseconds). | |
| unsigned long | last_change |
| The time of the last change (in milliseconds - no debounce). | |
| unsigned long | last_debounce |
| The time of the last change (in milliseconds - after debounce filtering). | |
| int | current_value |
| The switch's current value (after debounce filtering). | |
| int | last_value |
| The switch's value on the last read. | |
| int | pin |
| The pin to which the switch is connected. | |
| Type | type |
| The type of switch connected. | |
Handler for a switch input.
| enum SwitchInput::Type |
| SwitchInput::SwitchInput | ( | int | pin, |
| unsigned long | debounce = DEFAULT_DEBOUNCE, |
||
| Type | type = pull_up_internal |
||
| ) |
Constructor.
| pin | The number of the switch to which the pin is connected. |
| debounce | The debounce time (in milliseconds). |
| type | The type of switch connected. |
| bool SwitchInput::is_closed | ( | ) |
Checks to see if the switch is closed.
| bool SwitchInput::is_open | ( | ) |
Checks to see if the switch is open.
| bool SwitchInput::loop | ( | ) | [protected, virtual] |
| unsigned long SwitchInput::time_closed | ( | ) |
Checks the length of time for which the switch has been closed.
| unsigned long SwitchInput::time_open | ( | ) |
Checks the length of time for which the switch has been open.
1.7.3