Documentation updates and formatting.
Arduino 1.0 compatibility.
This commit is contained in:
63
button.h
63
button.h
@@ -1,8 +1,8 @@
|
||||
/*----------------------------------------------------------------------*
|
||||
* button.h -- Library for reading momentary contact switches like *
|
||||
* tactile button switches. *
|
||||
* *
|
||||
* Jack Christensen 11 May 2011 *
|
||||
* button.h -- Library for reading momentary contact switches like *
|
||||
* tactile button switches. *
|
||||
* *
|
||||
* Jack Christensen 11 May 2011 *
|
||||
* *
|
||||
* This work is licensed under the Creative Commons Attribution- *
|
||||
* ShareAlike 3.0 Unported License. To view a copy of this license, *
|
||||
@@ -10,31 +10,36 @@
|
||||
* letter to Creative Commons, 171 Second Street, Suite 300, *
|
||||
* San Francisco, California, 94105, USA. *
|
||||
*----------------------------------------------------------------------*/
|
||||
#ifndef button_h
|
||||
#define button_h
|
||||
#include "WProgram.h"
|
||||
class button
|
||||
#ifndef Button_h
|
||||
#define Button_h
|
||||
#if ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
class Button
|
||||
{
|
||||
public:
|
||||
button(uint8_t pin, uint8_t puEnabled, uint8_t invert, uint32_t dbTime);
|
||||
uint8_t read();
|
||||
uint8_t isPressed();
|
||||
uint8_t isReleased();
|
||||
uint8_t wasPressed();
|
||||
uint8_t wasReleased();
|
||||
uint8_t pressedFor(uint32_t ms);
|
||||
uint8_t releasedFor(uint32_t ms);
|
||||
uint32_t lastChange();
|
||||
private:
|
||||
uint8_t _pin; //arduino pin number
|
||||
uint8_t _puEnabled; //internal pullup resistor enabled
|
||||
uint8_t _invert; //if 0, interpret high state as pressed, else interpret low state as pressed
|
||||
uint8_t _state; //current button state
|
||||
uint8_t _lastState; //previous button state
|
||||
uint8_t _changed; //state changed since last read
|
||||
uint32_t _time; //time of current state (all times are in ms)
|
||||
uint32_t _lastTime; //time of previous state
|
||||
uint32_t _lastChange; //time of last state change
|
||||
uint32_t _dbTime; //debounce time
|
||||
public:
|
||||
Button(uint8_t pin, uint8_t puEnable, uint8_t invert, uint32_t dbTime);
|
||||
uint8_t read();
|
||||
uint8_t isPressed();
|
||||
uint8_t isReleased();
|
||||
uint8_t wasPressed();
|
||||
uint8_t wasReleased();
|
||||
uint8_t pressedFor(uint32_t ms);
|
||||
uint8_t releasedFor(uint32_t ms);
|
||||
uint32_t lastChange();
|
||||
|
||||
private:
|
||||
uint8_t _pin; //arduino pin number
|
||||
uint8_t _puEnable; //internal pullup resistor enabled
|
||||
uint8_t _invert; //if 0, interpret high state as pressed, else interpret low state as pressed
|
||||
uint8_t _state; //current button state
|
||||
uint8_t _lastState; //previous button state
|
||||
uint8_t _changed; //state changed since last read
|
||||
uint32_t _time; //time of current state (all times are in ms)
|
||||
uint32_t _lastTime; //time of previous state
|
||||
uint32_t _lastChange; //time of last state change
|
||||
uint32_t _dbTime; //debounce time
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user