New features:
- Debouncing detection
- Button repeat improved
- New parameter in constructor, allowing the use of analog buttons
Get it while it's fresh from http://www.arduino.cc/playground/Code/AdvButton
A blog about my adventures while learning electronics
#include< AdvButton.h >
#include < ButtonManager.h >
See the file buttondemo.pde, included in the zip, for an example.
#define PINBUTTON1 2 #define PINBUTTON2 3 #define PINLIGHT1 8 #define PINLIGHT2 9 AdvButton but1 = AdvButton(PINBUTTON1,OnKeyPressBut1,100,1000); AdvButton but2 = AdvButton(PINBUTTON2,NULL,OnKeyDownBut2,OnKeyUpBut2);
Button 1 will generate a keypress event upon pressing the button at pin 2. After a short delay (1000 milliseconds), every 100 milliseconds the keypress event is raise again. Until the button is released.
void OnKeyPressBut1(AdvButton* but) { digitalWrite(PINLIGHT1,HIGH); delay(5); digitalWrite(PINLIGHT1,LOW); } void OnKeyDownBut2(AdvButton* but) { digitalWrite(PINLIGHT2,HIGH); } void OnKeyUpBut2(AdvButton* but) { digitalWrite(PINLIGHT2,LOW); }
Last is the adding a call to the buttonmanager to update the button states:
void loop() { ButtonManager::instance()->checkButtons(); }