-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathExample1_PrintButtonStatus.ino
43 lines (35 loc) · 1.38 KB
/
Example1_PrintButtonStatus.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/******************************************************************************
Checks whether the button is pressed, and then prints its status over serial!
Fischer Moseley @ SparkFun Electronics
Original Creation Date: June 28, 2019
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
Hardware Connections:
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
Plug the button into the shield
Print it to the serial monitor at 115200 baud.
Distributed as-is; no warranty is given.
******************************************************************************/
#include <SparkFun_Qwiic_Button.h>
QwiicButton button;
void setup() {
Serial.begin(115200);
Serial.println("Qwiic button examples");
Wire.begin(); //Join I2C bus
//check if button will acknowledge over I2C
if (button.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
while (1);
}
Serial.println("Button acknowledged.");
}
void loop() {
//check if button is pressed, and tell us if it is!
if (button.isPressed() == true) {
Serial.println("The button is pressed!");
while (button.isPressed() == true)
delay(10); //wait for user to stop pressing
Serial.println("The button is not pressed!");
}
delay(20); //Don't hammer too hard on the I2C bus
}