mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-11-18 22:59:28 +00:00
Add Button
This commit is contained in:
29
lib/Button/examples/basic_usage/basic_usage.ino
Normal file
29
lib/Button/examples/basic_usage/basic_usage.ino
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <Button.h>
|
||||
|
||||
Button button1(2); // Connect your button between pin 2 and GND
|
||||
Button button2(3); // Connect your button between pin 3 and GND
|
||||
Button button3(4); // Connect your button between pin 4 and GND
|
||||
|
||||
void setup() {
|
||||
button1.begin();
|
||||
button2.begin();
|
||||
button3.begin();
|
||||
|
||||
while (!Serial) { }; // for Leos
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (button1.pressed())
|
||||
Serial.println("Button 1 pressed");
|
||||
|
||||
if (button2.released())
|
||||
Serial.println("Button 2 released");
|
||||
|
||||
if (button3.toggled()) {
|
||||
if (button3.read() == Button::PRESSED)
|
||||
Serial.println("Button 3 has been pressed");
|
||||
else
|
||||
Serial.println("Button 3 has been released");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user