I will be maintaining my libraries here: https://bit.ly/pATDBi I am the lead developer for libraries that ship with the Wiring distribution. As per version 1.0 - Wiring will support Arduino boards. You are welcome to check it out! https://wiring.org.co/download/
Button Library for Arduino Author: Alexander Brevig Contact: alexanderbrevig@gmail.com
Note: Alexander has ported Button to Wiring, and is currently maintaining it at http://wiring.uniandes.edu.co/source/trunk/wiring/firmware/libraries/Button/ A current Arduino of his Wiring version can be found at http://github.com/tigoe/Button. This version is compatible with the current development version of Arduino and should be compatible with version 1.0 and forward''
1.6 2009-05-05: Added uniquePress():bool
1.6 2009-05-05: Added uniquePress():bool
1.5 2009-04-24: Added stateChanged():bool
1.4 2009-04-24: Added wasPressed():bool
1.3 2009-04-12: Constructor that only requires a buttonPin. Presumes PULLDOWN
1.2 2009-04-10: Name changed from Switch to Button
1.1 2009-04-07: Altered API
1.0 2008-10-23: Initial Release
Button is a library for the Arduino.
It is created to help Hardware Abstraction, and readability of code. It hides the pinMode, and digitalRead calls for the user.
Button library is part of the Hardware Abstraction libraries.
Also a part of the tutorial: How to extend libraries using Hierarchy.
Download here:
Attach:Button.zip (for version 0022 and previous)
version for Arduino 1.0
Put the Button folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Button".
Once the library is imported, an '#include <Button.h>' line will appear at the top of your Sketch.
Button(byte buttonPin,byte buttonMode)
Button button = Button(12,PULLUP);
Instanciates a Button object with a digital pin number (12), and a PULLUP (or PULLDOWN) configuration.
Changes the Button mode to a pullup configuration
Changes the Button mode to a pulldown configuration
Checks to see if the button is pressed and returns true if it is.
Checks to see if the button was pressed the last time isPressed() was called, and returns true if it was.
Checks to see if the state of the button has changed. Such as from pressed to released or released to pressed. Returns true if state has changed since last isPressed() call.
Checks to see if the state of the button has changed AND the button is pressed. This will only return true the first time the button has been pressed. (As opposed to the isPressed() which will return true as long as the button is pressed.
How can I use multiple buttons?
Button is a class. Therefore to Button multiple digital pins, you must create an instance for each of them. In the example above, a Button instance (called button) for pin 12 is created on line 6. If you create several buttons, give each a better name then button, use something that says what it does:
Button lightOn = Button(12,PULLUP);
To Button an additional pin (pin 4 for example), you could create the following instance called nextStep:
Button nextStep = Button(4,PULLUP);
And now it's just to call the isPressed() on the button you are interested in getting the state of:
//check buttones if (lightOn.isPressed()){ someFunction(); } if (nextStep.isPressed()) { someOtherFunction(); }
Part of AlphaBeta Libraries. | |
Last Modified: | November 30, 2018, at 01:26 AM |
By: | pert |