Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Member Functions | List of all members
ToggleButton Class Reference

#include <ToggleButton.h>

Public Member Functions

 ToggleButton (uint8_t pin, bool pullup=true)
 
void begin (bool startState=false, uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay)
 
void update ()
 
bool on ()
 

Detailed Description

PushButton which toggles state.

Push once - on. Push again - off.

Definition at line 9 of file ToggleButton.h.

Constructor & Destructor Documentation

◆ ToggleButton()

ToggleButton::ToggleButton ( uint8_t  pin,
bool  pullup = true 
)

Constructor.

Parameters
pinthe pin which he button is connected to.
pullupsets the logic type for the button.

Note: if pullup is true the logic of the button is inverted - i.e. when the pin in pulled to ground, the button is considered to be pushed/on. The default is pullup, meaning that a LOW state on the pin means the button is on. Whilst this is a bit counter-intuitive, it is preferred as a floating pin will revert to off more readily than with non-pullup logic.

Definition at line 3 of file ToggleButton.cpp.

Member Function Documentation

◆ begin()

void ToggleButton::begin ( bool  startState = false,
uint8_t  threshold = AbstractDebouncedButton::DefaultThreshold,
uint8_t  delay = AbstractDebouncedButton::DefaultButtonDelay 
)

Initialization.

Parameters
startStatewhich state (on or off) the toggle starts in.
thresholdhow many tests of the pin must match for a press detection.
delaynumber of ms between tests of press detection.

Should be called from setup(), or at any rate, before other members are called. This will set the pinMode. The minimum time it takes for button presses / released to register is threshold * delay.

Definition at line 8 of file ToggleButton.cpp.

Here is the call graph for this function:

◆ on()

bool ToggleButton::on ( )

Test toggle state.

Returns
true if the toggle is on, else false.

Definition at line 22 of file ToggleButton.cpp.

◆ update()

void ToggleButton::update ( )

Allocate Timeslice.

This method must be called frequently - usually from loop().

Definition at line 14 of file ToggleButton.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: