Skip to content

Nick507/SmallButton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmallButton

Button library for arduino with support of almost use cases and optimized memory footprint

Size of SmallButton class - 4 bytes.

Features

  • Single button press
  • Single press and repeat
  • Press or release
  • Release
  • Get current state
  • Support invert flag: active button state can be 0 or 1
  • Configure pullup resistor

Library configuration macro:
SMALL_BUTTON_FILTER_TIME_MS - filter time for debouncing (default 50ms)
SMALL_BUTTON_REPEAT_DELAY_MS - delay time before first repeat (default 700ms)
SMALL_BUTTON_REPEAT_EVERY_MS - time interval between repeat (default 80ms)

To override these settings, add define statement before include library header, for example:
#define SMALL_BUTTON_FILTER_TIME_MS 100 // this line must be above include
#include "SmallButton.h"

Example of usage:

#include <SmallButton.h>

SmallButton button(1); // 1 - pin number

void setup() {
  Serial.begin(115200); // initialize serial to print log
  button.begin(); // initialize button
}

void loop() {
  if(button.get() & SmallButton::PRESS_OR_REPEAT) {
    Serial.println("Button pressed");
  }
}

Note: get() method returns bit flags with all events, so DO NOT call it in a way:

if((button.get() & SmallButton::PRESS) || (button.get() & SmallButton::REPEAT))

because you may skip events. Use masks from SmallButton::EventMask, or store result value in a variable and then deal with it.

About

Button library for arduino with support of almost use cases and optimized memory footprint

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages