From bb1df2994c50330a8f93a7d8853dccf633e6a5f1 Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Thu, 16 Nov 2023 13:49:12 -0700 Subject: [PATCH 1/6] Bump version number to v2.0.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 142c334..e5b9a89 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # http://packaging.python.org/en/latest/tutorial.html#version - version='2.0.1', + version='2.0.2', description='SparkFun Electronics qwiic button package', long_description='This package allows the user to: determine whether or not the button/switch is pressed or has been clicked, \ From 811e1645b843e3342b113bf23779b039035b6166 Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Thu, 16 Nov 2023 13:50:02 -0700 Subject: [PATCH 2/6] Remove __future__dependency For anyone still using Python 2.x, please switch to Python 3.x :) --- examples/qwiic_button_ex1_buttonPress.py | 1 - examples/qwiic_button_ex2_LEDon.py | 1 - examples/qwiic_button_ex3_LEDconfig.py | 1 - examples/qwiic_button_ex4_queueUsage.py | 1 - examples/qwiic_button_ex5_popQueue.py | 1 - examples/qwiic_button_ex6_changeI2CAddress.py | 1 - examples/qwiic_button_ex7_2Buttons.py | 1 - 7 files changed, 7 deletions(-) diff --git a/examples/qwiic_button_ex1_buttonPress.py b/examples/qwiic_button_ex1_buttonPress.py index 627314a..0dc4a8f 100755 --- a/examples/qwiic_button_ex1_buttonPress.py +++ b/examples/qwiic_button_ex1_buttonPress.py @@ -39,7 +39,6 @@ #================================================================================== # Example 1 -from __future__ import print_function import qwiic_button import time import sys diff --git a/examples/qwiic_button_ex2_LEDon.py b/examples/qwiic_button_ex2_LEDon.py index d67558a..1575e4c 100755 --- a/examples/qwiic_button_ex2_LEDon.py +++ b/examples/qwiic_button_ex2_LEDon.py @@ -39,7 +39,6 @@ #================================================================================== # Example 2 -from __future__ import print_function import qwiic_button import time import sys diff --git a/examples/qwiic_button_ex3_LEDconfig.py b/examples/qwiic_button_ex3_LEDconfig.py index 53165c4..baa08f3 100755 --- a/examples/qwiic_button_ex3_LEDconfig.py +++ b/examples/qwiic_button_ex3_LEDconfig.py @@ -39,7 +39,6 @@ #================================================================================== # Example 3 -from __future__ import print_function import qwiic_button import time import sys diff --git a/examples/qwiic_button_ex4_queueUsage.py b/examples/qwiic_button_ex4_queueUsage.py index edaf90b..2df0001 100755 --- a/examples/qwiic_button_ex4_queueUsage.py +++ b/examples/qwiic_button_ex4_queueUsage.py @@ -38,7 +38,6 @@ #================================================================================== # Example 4 -from __future__ import print_function import qwiic_button import time import sys diff --git a/examples/qwiic_button_ex5_popQueue.py b/examples/qwiic_button_ex5_popQueue.py index 561f53a..15fac7e 100755 --- a/examples/qwiic_button_ex5_popQueue.py +++ b/examples/qwiic_button_ex5_popQueue.py @@ -38,7 +38,6 @@ #================================================================================== # Example 5 -from __future__ import print_function import qwiic_button import time import sys diff --git a/examples/qwiic_button_ex6_changeI2CAddress.py b/examples/qwiic_button_ex6_changeI2CAddress.py index 16de3ad..950d321 100755 --- a/examples/qwiic_button_ex6_changeI2CAddress.py +++ b/examples/qwiic_button_ex6_changeI2CAddress.py @@ -39,7 +39,6 @@ #================================================================================== # Example 5 -from __future__ import print_function import qwiic_i2c import qwiic_button import time diff --git a/examples/qwiic_button_ex7_2Buttons.py b/examples/qwiic_button_ex7_2Buttons.py index 4a2bd58..ecc849d 100755 --- a/examples/qwiic_button_ex7_2Buttons.py +++ b/examples/qwiic_button_ex7_2Buttons.py @@ -41,7 +41,6 @@ #================================================================================== # Example 7 -from __future__ import print_function import qwiic_i2c import qwiic_button import time From 04d66ce06b8b9fd574e378ea8cb77ef0a350daae Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Thu, 16 Nov 2023 13:50:29 -0700 Subject: [PATCH 3/6] Remove unused imports --- examples/qwiic_button_ex6_changeI2CAddress.py | 1 - examples/qwiic_button_ex7_2Buttons.py | 1 - qwiic_button.py | 1 - 3 files changed, 3 deletions(-) diff --git a/examples/qwiic_button_ex6_changeI2CAddress.py b/examples/qwiic_button_ex6_changeI2CAddress.py index 950d321..6342636 100755 --- a/examples/qwiic_button_ex6_changeI2CAddress.py +++ b/examples/qwiic_button_ex6_changeI2CAddress.py @@ -39,7 +39,6 @@ #================================================================================== # Example 5 -import qwiic_i2c import qwiic_button import time import sys diff --git a/examples/qwiic_button_ex7_2Buttons.py b/examples/qwiic_button_ex7_2Buttons.py index ecc849d..80346dd 100755 --- a/examples/qwiic_button_ex7_2Buttons.py +++ b/examples/qwiic_button_ex7_2Buttons.py @@ -41,7 +41,6 @@ #================================================================================== # Example 7 -import qwiic_i2c import qwiic_button import time import sys diff --git a/qwiic_button.py b/qwiic_button.py index 1c4219f..29cc400 100755 --- a/qwiic_button.py +++ b/qwiic_button.py @@ -50,7 +50,6 @@ """ #----------------------------------------------------------------------------------- -import math import qwiic_i2c # Define the device name and I2C addresses. These are set in the class definition From f2848eeceac47ac374de97d13a2671c039f2cd64 Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Thu, 16 Nov 2023 14:02:21 -0700 Subject: [PATCH 4/6] Replace raw_input() with input() Is anyone still using Python 2.x? --- examples/qwiic_button_ex5_popQueue.py | 2 +- examples/qwiic_button_ex6_changeI2CAddress.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/qwiic_button_ex5_popQueue.py b/examples/qwiic_button_ex5_popQueue.py index 15fac7e..6291e31 100755 --- a/examples/qwiic_button_ex5_popQueue.py +++ b/examples/qwiic_button_ex5_popQueue.py @@ -57,7 +57,7 @@ def run_example(): while True: print("\nType 'p' to pop a value from the pressed queue.") - val = raw_input("Type 'c' to pop a value from the clicked queue: ") + val = input("Type 'c' to pop a value from the clicked queue: ") # If the character is c or C, then pop a value off of the clicked queue if val == "c" or val == "C": print("\nPopped Clicked Queue! The first value of clicked queue was: ") diff --git a/examples/qwiic_button_ex6_changeI2CAddress.py b/examples/qwiic_button_ex6_changeI2CAddress.py index 6342636..343a2a9 100755 --- a/examples/qwiic_button_ex6_changeI2CAddress.py +++ b/examples/qwiic_button_ex6_changeI2CAddress.py @@ -59,7 +59,7 @@ def run_example(): print("\nDon't use the 0x prefix. For instance, if you wanted to") print("\nchange the address to 0x5B, you would type 5B and hit enter.") - new_address = raw_input("\nNew Address: ") + new_address = input("\nNew Address: ") new_address = int(new_address, 16) # Check if the user entered a valid address From 7568f1fed98edf01591eda4b353dcb0c2b5eb542 Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Thu, 16 Nov 2023 14:05:01 -0700 Subject: [PATCH 5/6] Update example 7 Create variable that user can modify for the starting address, in case they already changed it. Fix address limits to be inclusive on 0x08 and 0x77 Add print statement specifying valid range --- examples/qwiic_button_ex6_changeI2CAddress.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/qwiic_button_ex6_changeI2CAddress.py b/examples/qwiic_button_ex6_changeI2CAddress.py index 343a2a9..ff7e7f3 100755 --- a/examples/qwiic_button_ex6_changeI2CAddress.py +++ b/examples/qwiic_button_ex6_changeI2CAddress.py @@ -43,10 +43,13 @@ import time import sys +# If you've already changed the I2C address, change this to the current address! +currentAddress = qwiic_button._QWIIC_BUTTON_DEFAULT_ADDRESS + def run_example(): print("\nSparkFun Qwiic Button Example 6") - my_button = qwiic_button.QwiicButton() + my_button = qwiic_button.QwiicButton(currentAddress) if my_button.begin() == False: print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \ @@ -58,14 +61,15 @@ def run_example(): print("\nEnter a new I2C address for the Qwiic Button to use.") print("\nDon't use the 0x prefix. For instance, if you wanted to") print("\nchange the address to 0x5B, you would type 5B and hit enter.") + print("Any address from 0x08 to 0x77 works.") new_address = input("\nNew Address: ") new_address = int(new_address, 16) # Check if the user entered a valid address - if new_address > 0x08 and new_address < 0x77: print("\nCharacters received and new address valid!") print("\nAttempting to set Qwiic Button address...") + if new_address >= 0x08 and new_address <= 0x77: my_button.set_I2C_address(new_address) print("\nAddress successfully changed!") From d19372b96d6013904549b9f7ed324f90abacebeb Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Thu, 16 Nov 2023 14:06:30 -0700 Subject: [PATCH 6/6] Update example formatting Don't need so many newlines Slow down print loops to 0.1s delays --- examples/qwiic_button_ex1_buttonPress.py | 6 +++--- examples/qwiic_button_ex2_LEDon.py | 6 +++--- examples/qwiic_button_ex3_LEDconfig.py | 6 +++--- examples/qwiic_button_ex4_queueUsage.py | 13 +++++++----- examples/qwiic_button_ex5_popQueue.py | 8 ++++---- examples/qwiic_button_ex6_changeI2CAddress.py | 20 +++++++++---------- examples/qwiic_button_ex7_2Buttons.py | 6 +++--- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/examples/qwiic_button_ex1_buttonPress.py b/examples/qwiic_button_ex1_buttonPress.py index 0dc4a8f..2eab4b0 100755 --- a/examples/qwiic_button_ex1_buttonPress.py +++ b/examples/qwiic_button_ex1_buttonPress.py @@ -57,12 +57,12 @@ def run_example(): while True: if my_button.is_button_pressed() == True: - print("\nThe button is pressed!") + print("The button is pressed!") else: - print("\nThe button is not pressed!") + print("The button is not pressed!") - time.sleep(0.02) + time.sleep(0.1) if __name__ == '__main__': try: diff --git a/examples/qwiic_button_ex2_LEDon.py b/examples/qwiic_button_ex2_LEDon.py index 1575e4c..c4ec972 100755 --- a/examples/qwiic_button_ex2_LEDon.py +++ b/examples/qwiic_button_ex2_LEDon.py @@ -60,14 +60,14 @@ def run_example(): while True: if my_button.is_button_pressed() == True: - print("\nThe button is pressed!") + print("The button is pressed!") my_button.LED_on(brightness) else: - print("\nThe button is not pressed.") + print("The button is not pressed.") my_button.LED_off() - time.sleep(0.02) + time.sleep(0.1) if __name__ == '__main__': try: diff --git a/examples/qwiic_button_ex3_LEDconfig.py b/examples/qwiic_button_ex3_LEDconfig.py index baa08f3..f083e65 100755 --- a/examples/qwiic_button_ex3_LEDconfig.py +++ b/examples/qwiic_button_ex3_LEDconfig.py @@ -65,14 +65,14 @@ def run_example(): if my_button.is_button_pressed() == True: - print("\nThe button is pressed!") + print("The button is pressed!") my_button.LED_config(brightness, cycle_time, off_time) else: - print("\nThe button is not pressed.") + print("The button is not pressed.") my_button.LED_off() - time.sleep(0.02) # Let's not hammer too hard on the I2C bus + time.sleep(0.1) # Let's not hammer too hard on the I2C bus if __name__ == '__main__': try: diff --git a/examples/qwiic_button_ex4_queueUsage.py b/examples/qwiic_button_ex4_queueUsage.py index 2df0001..447eca2 100755 --- a/examples/qwiic_button_ex4_queueUsage.py +++ b/examples/qwiic_button_ex4_queueUsage.py @@ -59,22 +59,25 @@ def run_example(): # If the queue of pressed events is not empty if my_button.is_pressed_queue_empty() == False: # Then print the time since the last and first button press - print("\n" + str(my_button.time_since_last_press() / 1000.0) + "s since he button was last pressed ") + print(str(my_button.time_since_last_press() / 1000.0) + "s since he button was last pressed ") print(str(my_button.time_since_first_press() / 1000.0) +"s since the button was first pressed ") # If the queue is empty else: - print("\nButton Pressed Queue is empty! ") + print("Button Pressed Queue is empty! ") # If the queue of clicked events is not empty if my_button.is_clicked_queue_empty() == False: # Then print the time since the last and first button click - print("\n" + str(my_button.time_since_last_click() / 1000.0) + "s since the button was last clicked ") + print(str(my_button.time_since_last_click() / 1000.0) + "s since the button was last clicked ") print(str(my_button.time_since_first_click() / 1000.0) + "s since the button was first clicked") # If the queue is empty else: - print("\nButton Clicked Queue is empty!") + print("Button Clicked Queue is empty!") - time.sleep(0.02) # Let's not hammer too hard on the I2C bus + # Add some visual separation + print() + + time.sleep(0.1) # Let's not hammer too hard on the I2C bus if __name__ == '__main__': try: diff --git a/examples/qwiic_button_ex5_popQueue.py b/examples/qwiic_button_ex5_popQueue.py index 6291e31..c6e181f 100755 --- a/examples/qwiic_button_ex5_popQueue.py +++ b/examples/qwiic_button_ex5_popQueue.py @@ -56,18 +56,18 @@ def run_example(): while True: - print("\nType 'p' to pop a value from the pressed queue.") + print("Type 'p' to pop a value from the pressed queue.") val = input("Type 'c' to pop a value from the clicked queue: ") # If the character is c or C, then pop a value off of the clicked queue if val == "c" or val == "C": - print("\nPopped Clicked Queue! The first value of clicked queue was: ") + print("Popped Clicked Queue! The first value of clicked queue was: ") print(str(my_button.pop_clicked_queue() / 1000.0)) # If the character is p or P, then pop a value off of the pressed queue if val == "p" or val == "P": - print("\nPopped Pressed Queue!") + print("Popped Pressed Queue!") print(str(my_button.pop_clicked_queue() / 1000.0)) - time.sleep(0.02) # Let's not hammer too hard on the I2C bus + time.sleep(0.1) # Let's not hammer too hard on the I2C bus if __name__ == '__main__': try: diff --git a/examples/qwiic_button_ex6_changeI2CAddress.py b/examples/qwiic_button_ex6_changeI2CAddress.py index ff7e7f3..35340c2 100755 --- a/examples/qwiic_button_ex6_changeI2CAddress.py +++ b/examples/qwiic_button_ex6_changeI2CAddress.py @@ -58,32 +58,32 @@ def run_example(): print("\nButton ready!") - print("\nEnter a new I2C address for the Qwiic Button to use.") - print("\nDon't use the 0x prefix. For instance, if you wanted to") - print("\nchange the address to 0x5B, you would type 5B and hit enter.") + print("Enter a new I2C address for the Qwiic Button to use.") print("Any address from 0x08 to 0x77 works.") + print("Don't use the 0x prefix. For instance, if you wanted to") + print("change the address to 0x5B, you would type 5B and hit enter.") - new_address = input("\nNew Address: ") + new_address = input("New Address: ") new_address = int(new_address, 16) # Check if the user entered a valid address - print("\nCharacters received and new address valid!") - print("\nAttempting to set Qwiic Button address...") if new_address >= 0x08 and new_address <= 0x77: + print("Characters received and new address valid!") + print("Attempting to set Qwiic Button address...") my_button.set_I2C_address(new_address) - print("\nAddress successfully changed!") + print("Address successfully changed!") # Check that the Qwiic Button acknowledges on the new address time.sleep(0.02) if my_button.begin() == False: - print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \ + print("The Qwiic Button isn't connected to the system. Please check your connection", \ file=sys.stderr) else: - print("\nButton acknowledged on new address!") + print("Button acknowledged on new address!") else: - print("\nAddress entered not a valid I2C address") + print("Address entered not a valid I2C address") if __name__ == '__main__': try: diff --git a/examples/qwiic_button_ex7_2Buttons.py b/examples/qwiic_button_ex7_2Buttons.py index 80346dd..8e1aadf 100755 --- a/examples/qwiic_button_ex7_2Buttons.py +++ b/examples/qwiic_button_ex7_2Buttons.py @@ -66,13 +66,13 @@ def run_example(): # Check if button 1 is pressed if my_button1.is_button_pressed() == True: - print("\nButton 1 is pressed!") + print("Button 1 is pressed!") # Check if button2 is pressed if my_button2.is_button_pressed() == True: - print("\nButton 2 is pressed!") + print("Button 2 is pressed!") - time.sleep(0.02) # Don't hammer too hard on the I2C bus + time.sleep(0.1) # Don't hammer too hard on the I2C bus if __name__ == '__main__': try: