mthread 0.5
Public Types | Public Member Functions | Protected Member Functions | Private Attributes

SwitchInput Class Reference

Handler for a switch input. More...

#include <mthread.h>

Inheritance diagram for SwitchInput:
Thread

List of all members.

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.

Detailed Description

Handler for a switch input.


Member Enumeration Documentation

Types of switches.

Enumerator:
pull_up_internal 

Switch equipped with an internal pull-up resistor.

pull_up 

Switch equipped with an external pull-up resistor.

pull_down 

Switch equipped with a pull-down resistor.


Constructor & Destructor Documentation

SwitchInput::SwitchInput ( int  pin,
unsigned long  debounce = DEFAULT_DEBOUNCE,
Type  type = pull_up_internal 
)

Constructor.

Parameters:
pinThe number of the switch to which the pin is connected.
debounceThe debounce time (in milliseconds).
typeThe type of switch connected.

Member Function Documentation

bool SwitchInput::is_closed ( )

Checks to see if the switch is closed.

Returns:
true if the switch is closed, false otherwise.
bool SwitchInput::is_open ( )

Checks to see if the switch is open.

Returns:
true if the switch is open, false otherwise.
bool SwitchInput::loop ( ) [protected, virtual]

Main loop.

See also:
Thread::loop().

Reimplemented from Thread.

unsigned long SwitchInput::time_closed ( )

Checks the length of time for which the switch has been closed.

Returns:
The amount of time (in milliseconds) or 0 if the switch is open.
unsigned long SwitchInput::time_open ( )

Checks the length of time for which the switch has been open.

Returns:
The amount of time (in milliseconds) or 0 if the switch is closed.

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations Enumerator Defines