Skip to content

Commit 273b7a3

Browse files
authored
Merge pull request #3 from sparkfun/v2.0.2
V2.0.2
2 parents c7d4a19 + d19372b commit 273b7a3

9 files changed

+42
-45
lines changed

examples/qwiic_button_ex1_buttonPress.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#==================================================================================
4040
# Example 1
4141

42-
from __future__ import print_function
4342
import qwiic_button
4443
import time
4544
import sys
@@ -58,12 +57,12 @@ def run_example():
5857
while True:
5958

6059
if my_button.is_button_pressed() == True:
61-
print("\nThe button is pressed!")
60+
print("The button is pressed!")
6261

6362
else:
64-
print("\nThe button is not pressed!")
63+
print("The button is not pressed!")
6564

66-
time.sleep(0.02)
65+
time.sleep(0.1)
6766

6867
if __name__ == '__main__':
6968
try:

examples/qwiic_button_ex2_LEDon.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#==================================================================================
4040
# Example 2
4141

42-
from __future__ import print_function
4342
import qwiic_button
4443
import time
4544
import sys
@@ -61,14 +60,14 @@ def run_example():
6160
while True:
6261

6362
if my_button.is_button_pressed() == True:
64-
print("\nThe button is pressed!")
63+
print("The button is pressed!")
6564
my_button.LED_on(brightness)
6665

6766
else:
68-
print("\nThe button is not pressed.")
67+
print("The button is not pressed.")
6968
my_button.LED_off()
7069

71-
time.sleep(0.02)
70+
time.sleep(0.1)
7271

7372
if __name__ == '__main__':
7473
try:

examples/qwiic_button_ex3_LEDconfig.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#==================================================================================
4040
# Example 3
4141

42-
from __future__ import print_function
4342
import qwiic_button
4443
import time
4544
import sys
@@ -66,14 +65,14 @@ def run_example():
6665

6766
if my_button.is_button_pressed() == True:
6867

69-
print("\nThe button is pressed!")
68+
print("The button is pressed!")
7069
my_button.LED_config(brightness, cycle_time, off_time)
7170

7271
else:
73-
print("\nThe button is not pressed.")
72+
print("The button is not pressed.")
7473
my_button.LED_off()
7574

76-
time.sleep(0.02) # Let's not hammer too hard on the I2C bus
75+
time.sleep(0.1) # Let's not hammer too hard on the I2C bus
7776

7877
if __name__ == '__main__':
7978
try:

examples/qwiic_button_ex4_queueUsage.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#==================================================================================
3939
# Example 4
4040

41-
from __future__ import print_function
4241
import qwiic_button
4342
import time
4443
import sys
@@ -60,22 +59,25 @@ def run_example():
6059
# If the queue of pressed events is not empty
6160
if my_button.is_pressed_queue_empty() == False:
6261
# Then print the time since the last and first button press
63-
print("\n" + str(my_button.time_since_last_press() / 1000.0) + "s since he button was last pressed ")
62+
print(str(my_button.time_since_last_press() / 1000.0) + "s since he button was last pressed ")
6463
print(str(my_button.time_since_first_press() / 1000.0) +"s since the button was first pressed ")
6564
# If the queue is empty
6665
else:
67-
print("\nButton Pressed Queue is empty! ")
66+
print("Button Pressed Queue is empty! ")
6867

6968
# If the queue of clicked events is not empty
7069
if my_button.is_clicked_queue_empty() == False:
7170
# Then print the time since the last and first button click
72-
print("\n" + str(my_button.time_since_last_click() / 1000.0) + "s since the button was last clicked ")
71+
print(str(my_button.time_since_last_click() / 1000.0) + "s since the button was last clicked ")
7372
print(str(my_button.time_since_first_click() / 1000.0) + "s since the button was first clicked")
7473
# If the queue is empty
7574
else:
76-
print("\nButton Clicked Queue is empty!")
75+
print("Button Clicked Queue is empty!")
7776

78-
time.sleep(0.02) # Let's not hammer too hard on the I2C bus
77+
# Add some visual separation
78+
print()
79+
80+
time.sleep(0.1) # Let's not hammer too hard on the I2C bus
7981

8082
if __name__ == '__main__':
8183
try:

examples/qwiic_button_ex5_popQueue.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#==================================================================================
3939
# Example 5
4040

41-
from __future__ import print_function
4241
import qwiic_button
4342
import time
4443
import sys
@@ -57,18 +56,18 @@ def run_example():
5756

5857
while True:
5958

60-
print("\nType 'p' to pop a value from the pressed queue.")
61-
val = raw_input("Type 'c' to pop a value from the clicked queue: ")
59+
print("Type 'p' to pop a value from the pressed queue.")
60+
val = input("Type 'c' to pop a value from the clicked queue: ")
6261
# If the character is c or C, then pop a value off of the clicked queue
6362
if val == "c" or val == "C":
64-
print("\nPopped Clicked Queue! The first value of clicked queue was: ")
63+
print("Popped Clicked Queue! The first value of clicked queue was: ")
6564
print(str(my_button.pop_clicked_queue() / 1000.0))
6665
# If the character is p or P, then pop a value off of the pressed queue
6766
if val == "p" or val == "P":
68-
print("\nPopped Pressed Queue!")
67+
print("Popped Pressed Queue!")
6968
print(str(my_button.pop_clicked_queue() / 1000.0))
7069

71-
time.sleep(0.02) # Let's not hammer too hard on the I2C bus
70+
time.sleep(0.1) # Let's not hammer too hard on the I2C bus
7271

7372
if __name__ == '__main__':
7473
try:

examples/qwiic_button_ex6_changeI2CAddress.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@
3939
#==================================================================================
4040
# Example 5
4141

42-
from __future__ import print_function
43-
import qwiic_i2c
4442
import qwiic_button
4543
import time
4644
import sys
4745

46+
# If you've already changed the I2C address, change this to the current address!
47+
currentAddress = qwiic_button._QWIIC_BUTTON_DEFAULT_ADDRESS
48+
4849
def run_example():
4950

5051
print("\nSparkFun Qwiic Button Example 6")
51-
my_button = qwiic_button.QwiicButton()
52+
my_button = qwiic_button.QwiicButton(currentAddress)
5253

5354
if my_button.begin() == False:
5455
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
@@ -57,31 +58,32 @@ def run_example():
5758

5859
print("\nButton ready!")
5960

60-
print("\nEnter a new I2C address for the Qwiic Button to use.")
61-
print("\nDon't use the 0x prefix. For instance, if you wanted to")
62-
print("\nchange the address to 0x5B, you would type 5B and hit enter.")
61+
print("Enter a new I2C address for the Qwiic Button to use.")
62+
print("Any address from 0x08 to 0x77 works.")
63+
print("Don't use the 0x prefix. For instance, if you wanted to")
64+
print("change the address to 0x5B, you would type 5B and hit enter.")
6365

64-
new_address = raw_input("\nNew Address: ")
66+
new_address = input("New Address: ")
6567
new_address = int(new_address, 16)
6668

6769
# Check if the user entered a valid address
68-
if new_address > 0x08 and new_address < 0x77:
69-
print("\nCharacters received and new address valid!")
70-
print("\nAttempting to set Qwiic Button address...")
70+
if new_address >= 0x08 and new_address <= 0x77:
71+
print("Characters received and new address valid!")
72+
print("Attempting to set Qwiic Button address...")
7173

7274
my_button.set_I2C_address(new_address)
73-
print("\nAddress successfully changed!")
75+
print("Address successfully changed!")
7476
# Check that the Qwiic Button acknowledges on the new address
7577
time.sleep(0.02)
7678
if my_button.begin() == False:
77-
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
79+
print("The Qwiic Button isn't connected to the system. Please check your connection", \
7880
file=sys.stderr)
7981

8082
else:
81-
print("\nButton acknowledged on new address!")
83+
print("Button acknowledged on new address!")
8284

8385
else:
84-
print("\nAddress entered not a valid I2C address")
86+
print("Address entered not a valid I2C address")
8587

8688
if __name__ == '__main__':
8789
try:

examples/qwiic_button_ex7_2Buttons.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#==================================================================================
4242
# Example 7
4343

44-
from __future__ import print_function
45-
import qwiic_i2c
4644
import qwiic_button
4745
import time
4846
import sys
@@ -68,13 +66,13 @@ def run_example():
6866

6967
# Check if button 1 is pressed
7068
if my_button1.is_button_pressed() == True:
71-
print("\nButton 1 is pressed!")
69+
print("Button 1 is pressed!")
7270

7371
# Check if button2 is pressed
7472
if my_button2.is_button_pressed() == True:
75-
print("\nButton 2 is pressed!")
73+
print("Button 2 is pressed!")
7674

77-
time.sleep(0.02) # Don't hammer too hard on the I2C bus
75+
time.sleep(0.1) # Don't hammer too hard on the I2C bus
7876

7977
if __name__ == '__main__':
8078
try:

qwiic_button.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"""
5151
#-----------------------------------------------------------------------------------
5252

53-
import math
5453
import qwiic_i2c
5554

5655
# Define the device name and I2C addresses. These are set in the class definition

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
# Versions should comply with PEP440. For a discussion on single-sourcing
5353
# the version across setup.py and the project code, see
5454
# http://packaging.python.org/en/latest/tutorial.html#version
55-
version='2.0.1',
55+
version='2.0.2',
5656

5757
description='SparkFun Electronics qwiic button package',
5858
long_description='This package allows the user to: determine whether or not the button/switch is pressed or has been clicked, \

0 commit comments

Comments
 (0)