Major update

imported some improvements from user "bartebor"
- fixed some timing issues
- added button-support via #ifdefine
- worked on penarm-shaking-bug
- restructured some codesegments
This commit is contained in:
cocktailyogi
2015-05-05 22:27:01 +02:00
parent 269591d8d0
commit 6505252c20
6 changed files with 264 additions and 180 deletions

59
button.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* button.h
*
* Created: 04.05.2015 21:38:42
* Author: Yogi
*/
#ifndef __BUTTON_H__
#define __BUTTON_H__
#include <Arduino.h>
#define debounceDelay 50
typedef void (*ActionCb)(void);
class Button
{
private:
long debounce;
byte state:1;
byte lastState:1;
byte pin;
ActionCb action;
Button( const Button &c );
Button& operator=( const Button &c );
public:
Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), action(a), pin(p) {} ;
void check() {
byte b = digitalRead(pin);
long t = millis();
if (b != lastState) {
debounce = t;
}
if ((t - debounce) > debounceDelay) {
if (b != state) {
state = b;
if (!state) {
(*action)();
}
}
}
lastState = b;
};
}; //button
#endif //__BUTTON_H__