Skip to content

Commit fd261a8

Browse files
committed
Cleaning up examples
Names and redundant versions
1 parent 04ed128 commit fd261a8

File tree

17 files changed

+153
-693
lines changed

17 files changed

+153
-693
lines changed
Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,43 @@
11
/******************************************************************************
2-
Checks whether the button is pressed, and then prints its status over serial!
2+
Checks whether the button is pressed, and then prints its status over serial!
33
4-
Fischer Moseley @ SparkFun Electronics
5-
Original Creation Date: June 28, 2019
4+
Fischer Moseley @ SparkFun Electronics
5+
Original Creation Date: June 28, 2019
66
7-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
8-
local, and you've found our code helpful, please buy us a round!
7+
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
8+
local, and you've found our code helpful, please buy us a round!
99
10-
Hardware Connections:
11-
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
12-
Plug the button into the shield
13-
Print it to the serial monitor at 115200 baud.
10+
Hardware Connections:
11+
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
12+
Plug the button into the shield
13+
Print it to the serial monitor at 115200 baud.
1414
15-
Distributed as-is; no warranty is given.
15+
Distributed as-is; no warranty is given.
1616
******************************************************************************/
1717

1818
#include <SparkFun_Qwiic_Button.h>
1919
QwiicButton button;
2020

21-
void setup(){
22-
Serial.begin(115200);
23-
Wire.begin(); //Join I2C bus
24-
Wire.setClock(400000); //Set I2C clock speed to 400kHz
25-
button.begin(DEFAULT_BUTTON_ADDRESS); // Initialize our button! Set to DEFAULT_SWITCH_ADDRESS if you're using a
26-
// switch, or whatever the I2C address of your device is
27-
28-
//check if button will acknowledge over I2C
29-
if(button.isConnected()){
30-
Serial.println("Device will acknowledge!");
31-
}
32-
33-
else {
34-
Serial.println("Device did not acknowledge! Freezing.");
35-
while(1);
36-
}
21+
void setup() {
22+
Serial.begin(115200);
23+
Serial.println("Qwiic button examples");
24+
Wire.begin(); //Join I2C bus
25+
26+
//check if button will acknowledge over I2C
27+
if (button.begin() == false) {
28+
Serial.println("Device did not acknowledge! Freezing.");
29+
while (1);
30+
}
31+
Serial.println("Button acknowledged.");
3732
}
3833

39-
void loop(){
40-
//check if button is pressed, and tell us if it is!
41-
if(button.isPressed()){
42-
Serial.println("The button is pressed!");
43-
}
44-
45-
else {
46-
Serial.println("The button is not pressed.");
47-
}
48-
49-
delay(20); //Don't hammer too hard on the I2C bus
50-
}
34+
void loop() {
35+
//check if button is pressed, and tell us if it is!
36+
if (button.isPressed() == true) {
37+
Serial.println("The button is pressed!");
38+
while (button.isPressed() == true)
39+
delay(10); //wait for user to stop pressing
40+
Serial.println("The button is not pressed!");
41+
}
42+
delay(20); //Don't hammer too hard on the I2C bus
43+
}

examples/Example1_PrintButtonStatus_newFirmware/Example1_PrintButtonStatus_newFirmware.ino

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,50 @@
11
/******************************************************************************
2-
Turns on the Button's built in LED when pressed, and prints status over Serial!
2+
Turns on the Button's built in LED when pressed, and prints status over Serial!
33
4-
Fischer Moseley @ SparkFun Electronics
5-
Original Creation Date: July 24, 2019
4+
Fischer Moseley @ SparkFun Electronics
5+
Original Creation Date: July 24, 2019
66
7-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
8-
local, and you've found our code helpful, please buy us a round!
7+
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
8+
local, and you've found our code helpful, please buy us a round!
99
10-
Hardware Connections:
11-
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
12-
Plug the button into the shield
13-
Print it to the serial monitor at 115200 baud.
10+
Hardware Connections:
11+
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
12+
Plug the button into the shield
13+
Print it to the serial monitor at 115200 baud.
1414
15-
Distributed as-is; no warranty is given.
15+
Distributed as-is; no warranty is given.
1616
******************************************************************************/
1717

1818
#include <SparkFun_Qwiic_Button.h>
1919
QwiicButton button;
2020
uint8_t brightness = 100; //The brightness to set the LED to when the button is pushed
2121
//Can be any value between 0 (off) and 255 (max)
2222

23-
void setup(){
24-
Serial.begin(115200);
25-
Wire.begin(); //Join I2C bus
26-
Wire.setClock(400000); //Set the I2C clock speed to 400kHz
27-
button.begin(DEFAULT_BUTTON_ADDRESS); // Initialize our button! Set to DEFAULT_SWITCH_ADDRESS if you're using a
28-
// switch, or whatever the I2C address of your device is
23+
void setup() {
24+
Serial.begin(115200);
25+
Serial.println("Qwiic button examples");
26+
Wire.begin(); //Join I2C bus
2927

30-
//check if button will acknowledge over I2C
31-
if(button.isConnected()){
32-
Serial.println("Device will acknowledge!");
33-
}
28+
//check if button will acknowledge over I2C
29+
if (button.begin() == false) {
30+
Serial.println("Device did not acknowledge! Freezing.");
31+
while (1);
32+
}
33+
Serial.println("Button acknowledged.");
3434

35-
else {
36-
Serial.println("Device did not acknowledge! Freezing.");
37-
while(1);
38-
}
35+
//Start with the LED off
36+
button.LEDoff();
37+
}
3938

39+
void loop() {
40+
//check if button is pressed, and tell us if it is!
41+
if (button.isPressed() == true) {
42+
Serial.println("The button is pressed!");
43+
button.LEDon(brightness);
44+
while(button.isPressed() == true)
45+
delay(10); //wait for user to stop pressing
46+
Serial.println("The button is not pressed.");
4047
button.LEDoff();
48+
}
49+
delay(20); //Don't hammer too hard on the I2C bus
4150
}
42-
43-
void loop(){
44-
//check if button is pressed, and tell us if it is!
45-
if(button.isPressed()){
46-
Serial.println("The button is pressed!");
47-
button.LEDon(brightness);
48-
}
49-
50-
else {
51-
Serial.println("The button is not pressed.");
52-
button.LEDoff();
53-
}
54-
delay(20); //Don't hammer too hard on the I2C bus
55-
}

examples/Example2_LightWhenPressed_newFirmware/Example2_LightWhenPressed_newFirmware.ino

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,51 @@
11
/******************************************************************************
2-
Checks whether the button is pressed, and light it up if it is! Also prints
3-
status to the serial monitor.
2+
Checks whether the button is pressed, and light it up if it is! Also prints
3+
status to the serial monitor.
44
5-
Fischer Moseley @ SparkFun Electronics
6-
Original Creation Date: July 24, 2019
5+
Fischer Moseley @ SparkFun Electronics
6+
Original Creation Date: July 24, 2019
77
8-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
9-
local, and you've found our code helpful, please buy us a round!
8+
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
9+
local, and you've found our code helpful, please buy us a round!
1010
11-
Hardware Connections:
12-
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
13-
Plug the button into the shield
14-
Print it to the serial monitor at 115200 baud.
11+
Hardware Connections:
12+
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
13+
Plug the button into the shield
14+
Print it to the serial monitor at 115200 baud.
1515
16-
Distributed as-is; no warranty is given.
16+
Distributed as-is; no warranty is given.
1717
******************************************************************************/
1818

1919
#include <SparkFun_Qwiic_Button.h>
2020
QwiicButton button;
21-
uint8_t brightness = 170; //The maximum brightness of the pulsing LED. Can be between 0 (min) and 255 (max)
22-
uint16_t cycleTime = 500; //The total time for the pulse to take. Set to a bigger number for a slower pulse, or a smaller number for a faster pulse
23-
uint16_t offTime = 500; //The total time to stay off between pulses. Set to 0 to be pulsing continuously.
24-
25-
26-
void setup(){
27-
Serial.begin(115200);
28-
Wire.begin(); //Join I2C bus
29-
Wire.setClock(400000); //Set I2C clock to 400kHz
30-
button.begin(DEFAULT_BUTTON_ADDRESS); // Initialize our button! Set to DEFAULT_SWITCH_ADDRESS if you're using a
31-
// switch, or whatever the I2C address of your device is
32-
33-
//check if button will acknowledge over I2C
34-
if(button.isConnected()){
35-
Serial.println("Device will acknowledge!");
36-
}
37-
38-
else {
39-
Serial.println("Device did not acknowledge! Freezing.");
40-
while(1);
41-
}
21+
//Define LED characteristics
22+
uint8_t brightness = 250; //The maximum brightness of the pulsing LED. Can be between 0 (min) and 255 (max)
23+
uint16_t cycleTime = 1000; //The total time for the pulse to take. Set to a bigger number for a slower pulse, or a smaller number for a faster pulse
24+
uint16_t offTime = 200; //The total time to stay off between pulses. Set to 0 to be pulsing continuously.
25+
26+
void setup() {
27+
Serial.begin(115200);
28+
Serial.println("Qwiic button examples");
29+
Wire.begin(); //Join I2C bus
30+
31+
//check if button will acknowledge over I2C
32+
if (button.begin() == false) {
33+
Serial.println("Device did not acknowledge! Freezing.");
34+
while (1);
35+
}
36+
Serial.println("Button acknowledged.");
37+
button.LEDoff(); //start with the LED off
38+
}
4239

40+
void loop() {
41+
//check if button is pressed, and tell us if it is!
42+
if (button.isPressed() == true) {
43+
Serial.println("The button is pressed!");
44+
button.LEDconfig(brightness, cycleTime, offTime);
45+
while (button.isPressed() == true)
46+
delay(10); //wait for user to stop pressing
47+
Serial.println("The button is not pressed.");
4348
button.LEDoff();
49+
}
50+
delay(20); //let's not hammer too hard on the I2C bus
4451
}
45-
46-
void loop(){
47-
//check if button is pressed, and tell us if it is!
48-
if(button.isPressed()){
49-
Serial.println("The button is pressed!");
50-
button.LEDconfig(brightness, 1, cycleTime, offTime);
51-
}
52-
53-
else {
54-
Serial.println("The button is not pressed.");
55-
button.LEDoff();
56-
}
57-
58-
delay(20); //let's not hammer too hard on the I2C bus
59-
}

0 commit comments

Comments
 (0)