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

#include <AnalogInputButton.h>

Inheritance diagram for AnalogInputButton:
Inheritance graph

Public Member Functions

 AnalogInputButton (const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512)
 
void begin ()
 
bool on ()
 
- Public Member Functions inherited from AbstractButton
 AbstractButton ()
 

Protected Attributes

const uint8_t _pin
 
const bool _pullup
 
const uint16_t _analogThreshold
 

Detailed Description

Instantaneous button with a digital output, from an analog input.

AnalogInputButton models a digital push button or switch attached to an analog input. The API gives the user a logical pushed state via the on() method, which hides the analog to digital logic from the user of the class (choose logic params in constructor).

Usually, a digital DigitalInputButton will be better, but a few pins on some microcontrollers (A6, A7 on the Nano, for example), cannot read in digitial mode, so this lets those pins be used as buttons.

Definition at line 19 of file AnalogInputButton.h.

Constructor & Destructor Documentation

◆ AnalogInputButton()

AnalogInputButton::AnalogInputButton ( const uint8_t  pin,
const bool  pullup = true,
const uint16_t  analogThreshold = 512 
)

Constructor.

Parameters
pinthe pin which he button is connected to.
pullupif true pin==LOW means on, else pin==HIGH is on.
analogThresholdthe value above which the button is considered to be on.

Note: it is typical for digital buttons to be held high by a pullup resistor (either internal or external) pullup, and activated by pulling the pin to ground. This "inverted logic" is replicated here with the default value of pullup. However, there is no internal pullup resistor some analog pins, so an external pullup should be used where necessary.

Definition at line 4 of file AnalogInputButton.cpp.

Member Function Documentation

◆ begin()

void AnalogInputButton::begin ( )
virtual

Initialization.

It is typical to call the begin() method from the Arduino sketch's setup() function. This will call pinMode() for you, with arguments appropriate for the button logic type.

Reimplemented from AbstractButton.

Definition at line 11 of file AnalogInputButton.cpp.

Here is the caller graph for this function:

◆ on()

bool AnalogInputButton::on ( )
virtual

Test instantaneous input state.

Returns
true if the button is pushed, else false.

Implements AbstractButton.

Reimplemented in DebouncedAnalogButton.

Definition at line 16 of file AnalogInputButton.cpp.

Here is the caller graph for this function:

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