Skip to content

Commit 919b1b6

Browse files
committed
Bringing in copy of button library as starting point
1 parent 1f49d17 commit 919b1b6

File tree

16 files changed

+1293
-2
lines changed

16 files changed

+1293
-2
lines changed

ISSUE_TEMPLATE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Subject of the issue
2+
Describe your issue here.
3+
4+
### Your workbench
5+
* What development board or microcontroller are you using?
6+
* What version of hardware or breakout board are you using?
7+
* How is the breakout board wired to your microcontroller?
8+
* How is everything being powered?
9+
* Are there any additional details that may help us help you?
10+
11+
### Steps to reproduce
12+
Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue.
13+
14+
### Expected behavior
15+
Tell us what should happen
16+
17+
### Actual behavior
18+
Tell us what happens instead

LICENSE.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
SparkFun License Information
2+
============================
3+
4+
SparkFun uses two different licenses for our files — one for hardware and one for code.
5+
6+
Hardware
7+
---------
8+
9+
**SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).**
10+
11+
Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode).
12+
13+
You are free to:
14+
15+
Share — copy and redistribute the material in any medium or format
16+
Adapt — remix, transform, and build upon the material
17+
for any purpose, even commercially.
18+
The licensor cannot revoke these freedoms as long as you follow the license terms.
19+
Under the following terms:
20+
21+
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
22+
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
23+
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
24+
Notices:
25+
26+
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
27+
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
28+
29+
30+
Code
31+
--------
32+
33+
**SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).**
34+
35+
The MIT License (MIT)
36+
37+
Copyright (c) 2016 SparkFun Electronics
38+
39+
Permission is hereby granted, free of charge, to any person obtaining a copy
40+
of this software and associated documentation files (the "Software"), to deal
41+
in the Software without restriction, including without limitation the rights
42+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43+
copies of the Software, and to permit persons to whom the Software is
44+
furnished to do so, subject to the following conditions:
45+
46+
The above copyright notice and this permission notice shall be included in all
47+
copies or substantial portions of the Software.
48+
49+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55+
SOFTWARE.

README.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
1-
# SparkFun_Qwiic_Buzzer_Arduino_Library
2-
Arduino Library for the SparkFun Qwiic Buzzer
1+
SparkFun Qwiic Button Arduino Library [![Build Status](https://travis-ci.org/sparkfun/SparkFun_Qwiic_Button_Arduino_Library.svg?branch=master)](https://travis-ci.org/sparkfun/SparkFun_Qwiic_Button_Arduino_Library)
2+
========================================
3+
<table class="table table-hover table-striped table-bordered">
4+
<tr align="center">
5+
<td><a href="https://www.sparkfun.com/products/15932"><img src="https://cdn.sparkfun.com/assets/parts/1/4/5/7/3/15932-SparkFun_Qwiic_Button_-_Red-01.jpg"></a></td>
6+
<td><a href="https://www.sparkfun.com/products/15931"><img src="https://cdn.sparkfun.com/assets/parts/1/4/5/7/2/15931-SparkFun_Qwiic_Button_Breakout-01.jpg"></a></td>
7+
<td><a href="https://www.sparkfun.com/products/15591"><img src="https://cdn.sparkfun.com//assets/parts/1/4/1/9/8/15591-Qwiic_Arcade_-_Red-01a.jpg"></a></td>
8+
<td><a href="https://www.sparkfun.com/products/15592"><img src="https://cdn.sparkfun.com//assets/parts/1/4/1/9/9/15592-Qwiic_Arcade_-_Blue-01a.jpg"></a></td>
9+
<td><a href="https://www.sparkfun.com/products/15586"><img src="https://cdn.sparkfun.com//assets/parts/1/4/1/9/2/15586-Qwiic_Switch__without_microswitch_-01a.jpg"></a></td>
10+
</tr>
11+
<tr align="center">
12+
<td><a href="https://www.sparkfun.com/products/15932">SparkFun Qwiic Button - Red (BOB-15932)</a></td>
13+
<td><a href="https://www.sparkfun.com/products/15931">SparkFun Qwiic Button Breakout (BOB-15931)</a></td>
14+
<td><a href="https://www.sparkfun.com/products/15591">SparkFun Qwiic Arcade - Red (SPX-15591)</a></td>
15+
<td><a href="https://www.sparkfun.com/products/15592">SparkFun Qwiic Arcade - Blue (SPX-15592)</a></td>
16+
<td><a href="https://www.sparkfun.com/products/15586">SparkFun Qwiic Switch (SPX-15586)</a></td>
17+
</tr>
18+
</table>
19+
20+
21+
This library allows the user to:
22+
23+
* Determine whether or not the button/switch is pressed
24+
* Set the brightness of the onboard LED
25+
* Configure the onboard LED's "breathing" effect
26+
* Use button-based interrupts
27+
* Adjust the device's I<sup>2</sup>C address
28+
29+
30+
Repository Contents
31+
-------------------
32+
33+
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
34+
* **/src** - Source files for the library (.cpp, .h).
35+
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
36+
* **library.properties** - General library properties for the Arduino package manager.
37+
38+
Documentation
39+
--------------
40+
41+
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
42+
* **[Product Repository](https://github.com/sparkfun/Qwiic_Button)** - Main repository (including hardware files) for the SparkFun Qwiic Button Breakout Board.
43+
* **[Product Repository](https://github.com/sparkfunX/Qwiic_Switch)** - Main repository (including hardware files) for the SparkFun Qwiic Switch.
44+
* **[Product Repository](https://github.com/sparkfunX/Qwiic_Button)** - Main repository (including hardware files) for the SparkFun Qwiic Button.
45+
46+
Products that use this Library
47+
---------------------------------
48+
49+
* [*BOB-15932*](https://www.sparkfun.com/products/15932) - SparkFun Red Version with red LED pushbutton
50+
* [*BOB-16842*](https://www.sparkfun.com/products/16842) - SparkFun Red Version with green LED pushbutton
51+
* [*BOB-15931*](https://www.sparkfun.com/products/15931) - SparkFun Red Version without button
52+
* [*SPX-15584*](https://www.sparkfun.com/products/15584) - Original SparkX version of the Qwiic Button (Red LED)
53+
* [*SPX-15585*](https://www.sparkfun.com/products/15585) - Original SparkX version of the Qwiic Button (Blue LED)
54+
* [*SPX-15591*](https://www.sparkfun.com/products/15591) - Original SparkX version of the Qwiic Button (Arcade Red Pushbutton)
55+
* [*SPX-15592*](https://www.sparkfun.com/products/15592) - Original SparkX version of the Qwiic Button (Arcade Blue Pushbutton)
56+
* [*SPX-15586*](https://www.sparkfun.com/products/15586) - Original SparkX version of the Qwiic Button
57+
58+
Version History
59+
---------------
60+
61+
* [v1.0.1](https://github.com/sparkfun/SparkFun_Qwiic_Button_Arduino_Library/releases/tag/v1.0.1) - Arduino Library Specification Compliance
62+
* [v1.0.0](https://github.com/sparkfun/SparkFun_Qwiic_Button_Arduino_Library/releases/tag/v1.0.0) - Initial Public release.
63+
64+
License Information
65+
-------------------
66+
67+
This product is _**open source**_!
68+
69+
Please review the LICENSE.md file for license information.
70+
71+
If you have any questions or concerns on licensing, please contact techsupport@sparkfun.com.
72+
73+
Distributed as-is; no warranty is given.
74+
75+
- Your friends at SparkFun.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/******************************************************************************
2+
Checks whether the button is pressed, and then prints its status over serial!
3+
4+
Fischer Moseley @ SparkFun Electronics
5+
Original Creation Date: June 28, 2019
6+
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!
9+
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.
14+
15+
Distributed as-is; no warranty is given.
16+
******************************************************************************/
17+
18+
#include <SparkFun_Qwiic_Button.h>
19+
QwiicButton button;
20+
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.");
32+
}
33+
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+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/******************************************************************************
2+
Turns on the Button's built in LED when pressed, and prints status over Serial!
3+
4+
Fischer Moseley @ SparkFun Electronics
5+
Original Creation Date: July 24, 2019
6+
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!
9+
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.
14+
15+
Distributed as-is; no warranty is given.
16+
******************************************************************************/
17+
18+
#include <SparkFun_Qwiic_Button.h>
19+
QwiicButton button;
20+
uint8_t brightness = 100; //The brightness to set the LED to when the button is pushed
21+
//Can be any value between 0 (off) and 255 (max)
22+
23+
void setup() {
24+
Serial.begin(115200);
25+
Serial.println("Qwiic button examples");
26+
Wire.begin(); //Join I2C bus
27+
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.");
34+
35+
//Start with the LED off
36+
button.LEDoff();
37+
}
38+
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.");
47+
button.LEDoff();
48+
}
49+
delay(20); //Don't hammer too hard on the I2C bus
50+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/******************************************************************************
2+
Checks whether the button is pressed, and light it up if it is! Also prints
3+
status to the serial monitor.
4+
5+
Fischer Moseley @ SparkFun Electronics
6+
Original Creation Date: July 24, 2019
7+
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!
10+
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.
15+
16+
Distributed as-is; no warranty is given.
17+
******************************************************************************/
18+
19+
#include <SparkFun_Qwiic_Button.h>
20+
QwiicButton button;
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+
}
39+
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.");
48+
button.LEDoff();
49+
}
50+
delay(20); //let's not hammer too hard on the I2C bus
51+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/******************************************************************************
2+
Shows how to use the FIFO Queue on the Qwiic Button
3+
4+
Fischer Moseley @ SparkFun Electronics
5+
Original Creation Date: July 29, 2019
6+
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!
9+
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.
14+
15+
Distributed as-is; no warranty is given.
16+
******************************************************************************/
17+
18+
#include <SparkFun_Qwiic_Button.h>
19+
QwiicButton button;
20+
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.");
32+
}
33+
34+
void loop(){
35+
if(button.isPressedQueueEmpty() == false) { //if the queue of pressed events is not empty
36+
//then print the time since the last and first button press
37+
Serial.print(button.timeSinceLastPress()/1000.0);
38+
Serial.print("s since the button was last pressed ");
39+
Serial.print(button.timeSinceFirstPress()/1000.0);
40+
Serial.print("s since the button was first pressed ");
41+
}
42+
//if the queue of pressed events is empty, just print that the queue is empty!
43+
else {
44+
Serial.print("ButtonPressed Queue is empty! ");
45+
}
46+
47+
if(button.isClickedQueueEmpty() == false) { //if the queue of clicked events is not empty
48+
//then print the time since the last and first button click
49+
Serial.print(button.timeSinceLastClick()/1000.0);
50+
Serial.print("s since the button was last clicked ");
51+
Serial.print(button.timeSinceFirstClick()/1000.0);
52+
Serial.print("s since the button was first clicked");
53+
}
54+
//if the queue of clicked events is empty, just print that the queue is empty!
55+
else {
56+
Serial.print(" ButtonClicked Queue is empty!");
57+
}
58+
59+
Serial.println(); //print a new line to not clutter up the serial monitor
60+
61+
if(Serial.available()) { //if the user sent a character
62+
63+
uint8_t data = Serial.read();
64+
if(data == 'p' || data == 'P') { //if the character is p or P, then pop a value off of the pressed Queue
65+
long pressedPopped = button.popPressedQueue();
66+
Serial.print("Popped from PressedQueue: ");
67+
Serial.println(pressedPopped/1000.0);
68+
// Wait before continuing on
69+
delay(3000);
70+
}
71+
72+
if(data == 'c' || data == 'C') { //if the character is c or C, then pop a value off of the pressed Queue
73+
long clickedPopped = button.popClickedQueue();
74+
Serial.print("Popped from Clicked Queue: ");
75+
Serial.println(clickedPopped/1000.0);
76+
// Wait before continuing on
77+
delay(3000);
78+
}
79+
}
80+
delay(20); //let's not hammer too hard on the I2C bus
81+
}

0 commit comments

Comments
 (0)