Giter VIP home page Giter VIP logo

debounceswitch-test's Introduction

DebounceSwitch

A c++ class for de-bouncing a mechanical switch.

  • The required parameters are:

    • the GPIO input pin #
    • a flag that's true if using an internal pullup resistor, or false otherwise
    • a pair of callback functions that get called when the input pin goes either low or high
    • a debounce delay in milliseconds
  • The initPin() member function must be called first. It configures the input pin, and returns the inital state of the switch.

  • The readPin(debounceDelay) member function returns the current state (de-bounced), and calls the appropriate callback function whenever the pin's state changes.

#include "DebounceSwitch.h"

#define swPin 12                
#define intPullup true          // ! use internal pullup resistor?

void loCallback(), hiCallback();
DebounceSwitch mySwitch(swPin, intPullup, loCallback, hiCallback);

void setup() {
.
.
. 
  bool swStateInit = mySwitch.initPin();  // initialize switch
}

void loop() {
  int debounceDelay = 50;       // (ms)
  bool swState = mySwitch.readPin(debounceDelay); 
}

void loCallback() {
  Serial.println("Input just went LOW.");
}

void hiCallback() {
  Serial.println("Input just went HIGH.");
}

Included is an example Platform IO project. You can choose between platforms using a single pre-processor statement. Be sure to select the correct environment before compiling - see the screenshots below.

[env:nano_every]
platform = atmelmegaavr
board = nano_every
framework = arduino
monitor_speed = 115200

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
monitor_speed = 115200

Digital Inputs: Pullup vs. Pulldown Resistors

ESP8266 D1 Mini Pinout

Source: https://www.mischianti.org/2021/04/26/wemos-d1-mini-high-resolution-pinout-and-specs/

Source: https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

ESP32 Dev Kit C v4 Pinout

Source: https://forum.fritzing.org/t/esp32s-hiletgo-dev-boad-with-pinout-template/5357

Source: https://www.mischianti.org/2021/07/17/esp32-devkitc-v4-high-resolution-pinout-and-specs/

Arduino Nano Every Pinout

Source: https://docs.arduino.cc/hardware/nano-every/

debounceswitch-test's People

Contributors

bdubs-astro avatar bdwissman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.