Skip to content

codejnki/slacker.button

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slacker.button

An exceedingly simple button class to help with things. Utilizes a 200 ms debounce.

Version 2.0.0 Update

For version 2 I changed the include to be a .hpp file since I'm doing this as a cpp class.

Installation and usage

To install this library just place the entire sub folder in your library folder.

#include <button.hpp>

// The button class supports two different modes, momentary or switch
// Momentary will return a value while a button is actively being pressed
// Toggle will switch state on each button press much like a lightswitch

slacker::Button::ButtonType _buttonType = slacker::Button::ButtonType::Momentary;
slacker::Button _button(2, _buttonType);

// your code goes here

There is a new constructor that will take the debounce time as a parameter. Using the older constructor defaults to the 200 ms. Personally I think about 175ms debounce is pretty good.

Methods

ButtonPressed();

Will return true if the button has been pressed. Can be used in either toggle or momentary mode.

GetButtonCounter()

When the button is in toggle mode this will return a counter that increments each time the button is flipped to the on state.

ResetButtonCounter()

Will reset the counter back to zero.

ToDo

So I'm not terribly happy with this code at the moment.

  • Code refactor to clean up the two main button Methods
  • Implement a counter property
  • Implement a counter in momentary mode that tells you how long the button has been held down.

About

An arduino button class

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages