t3db0t-Button-3158831
code 

所属分类:其他
开发工具:Arduino
文件大小:10KB
下载次数:0
上传日期:2020-12-02 22:11:06
上 传 者Mjpk
说明:  Arduino button code file

文件列表:
t3db0t-Button-3158831 (0, 2019-03-23)
t3db0t-Button-3158831\AlphaLicense.txt (2282, 2019-03-23)
t3db0t-Button-3158831\Button.cpp (7337, 2019-03-23)
t3db0t-Button-3158831\Button.h (2053, 2019-03-23)
t3db0t-Button-3158831\Examples (0, 2019-03-23)
t3db0t-Button-3158831\Examples\Button (0, 2019-03-23)
t3db0t-Button-3158831\Examples\Button\.DS_Store (6148, 2019-03-23)
t3db0t-Button-3158831\Examples\Button\Button.ino (823, 2019-03-23)
t3db0t-Button-3158831\Examples\Callbacks (0, 2019-03-23)
t3db0t-Button-3158831\Examples\Callbacks\Callbacks.ino (1771, 2019-03-23)
t3db0t-Button-3158831\Examples\Debounce (0, 2019-03-23)
t3db0t-Button-3158831\Examples\Debounce\Debounce.ino (797, 2019-03-23)
t3db0t-Button-3158831\Examples\StateChanged (0, 2019-03-23)
t3db0t-Button-3158831\Examples\StateChanged\StateChanged.ino (672, 2019-03-23)
t3db0t-Button-3158831\Examples\UniquePress (0, 2019-03-23)
t3db0t-Button-3158831\Examples\UniquePress\UniquePress.ino (673, 2019-03-23)
t3db0t-Button-3158831\keywords.txt (634, 2019-03-23)

# New & Improved Arduino Button Library _by Ted Hayes, from code originally by Alexander Brevig & Tom Igoe_ The Arduino Button library makes it easy to do some very common but rather tedious tasks. Usually when you interact with a button (such as a momentary switch), you mainly want to detect the state change, not just the current state. You have to do something like: int lastState = 0; void loop(){ int currentState = digitalRead(11); if(currentState != lastState){ // do something } lastState = currentState; } It's not hard, just tedious. This new and improved Button library makes this much simpler but adds so much more. Now you can do it this way: Button button = Button(12); void onPress(Button& b){ Serial.print("onPress: "); Serial.println(b.pin); // will print out "onPress: 12" } void setup(){ Serial.begin(9600); // Assign callback function button.pressHandler(onPress); } void loop(){ // update the buttons' internals button.process(); } ## Features * Instance-based design `Button myButton(11);` * Automatic pull-up setting `Button myButton(11, BUTTON_PULLUP_INTERNAL);` * Simplified state-change detection: `if(button.isPressed()) ...` * Callback model `button.pressHandler(onPress)` * Built-in debouncing `// Sets 50ms debounce duration` `Button button = Button(12, BUTTON_PULLUP_INTERNAL, true, 50);` ## Installing To install, [download](https://github.com/virgildisgr4ce/Button/zipball/master) the library, extract it to ~/Documents/Arduino/libraries and rename the folder "Button." (Github generates a different name for the zip link.) Restart Arduino if it was already open. I hope you find this useful! Please report any bugs using the [Github issue tracker](https://github.com/virgildisgr4ce/Button/issues).

近期下载者

相关文件


收藏者