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

#include <MultiThrowSwitch.h>

Public Member Functions

 MultiThrowSwitch (uint8_t throws, const uint8_t pins[], bool sticky=false, bool pullup=true)
 
void begin (int startPosition=0, uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay)
 
void update ()
 
uint8_t position ()
 

Detailed Description

MultiThrowSwitch

For modelling things like rotary dials which can have one (or none) of a group of pins active at a given time, with a numeric position between 1 and the number of throws for the position of the switch.

Definition at line 13 of file MultiThrowSwitch.h.

Constructor & Destructor Documentation

◆ MultiThrowSwitch()

MultiThrowSwitch::MultiThrowSwitch ( uint8_t  throws,
const uint8_t  pins[],
bool  sticky = false,
bool  pullup = true 
)

Constructor.

Parameters
throwsthe number of throws (pins) for the switch.
pinsan array of pins (must be "throws" long). \patam sticky if true, stay with the last active position until a new position is active. If false then the position is 0 if no pins are active.
pullupsets the logic type for the various pins.

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 5 of file MultiThrowSwitch.cpp.

Member Function Documentation

◆ begin()

void MultiThrowSwitch::begin ( int  startPosition = 0,
uint8_t  threshold = AbstractDebouncedButton::DefaultThreshold,
uint8_t  delay = AbstractDebouncedButton::DefaultButtonDelay 
)

Initialization.

Parameters
startPositionwhich position is active at start (0 means automatic)
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 40 of file MultiThrowSwitch.cpp.

Here is the call graph for this function:

◆ position()

uint8_t MultiThrowSwitch::position ( )

Get switch position.

Returns
the lowest active pin as a number between 1 and the number of throws. If the object was constructed with the sticky parameter set, the last active pin is remembered, even if no pins are active when position() is called. If not pins are active and the sticky property was not set, this method returns 0.

Definition at line 76 of file MultiThrowSwitch.cpp.

◆ update()

void MultiThrowSwitch::update ( )

Allocate Timeslice.

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

Definition at line 53 of file MultiThrowSwitch.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

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