diff --git a/examples/qwiic_button_ex1_buttonPress.py b/examples/qwiic_button_ex1_buttonPress.py index 627314a..2eab4b0 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 @@ -58,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 d67558a..c4ec972 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 @@ -61,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 53165c4..f083e65 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 @@ -66,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 edaf90b..447eca2 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 @@ -60,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 561f53a..c6e181f 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 @@ -57,18 +56,18 @@ 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: ") + 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 16de3ad..35340c2 100755 --- a/examples/qwiic_button_ex6_changeI2CAddress.py +++ b/examples/qwiic_button_ex6_changeI2CAddress.py @@ -39,16 +39,17 @@ #================================================================================== # Example 5 -from __future__ import print_function -import qwiic_i2c import qwiic_button 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", \ @@ -57,31 +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 = raw_input("\nNew Address: ") + new_address = input("New 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: + 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 4a2bd58..8e1aadf 100755 --- a/examples/qwiic_button_ex7_2Buttons.py +++ b/examples/qwiic_button_ex7_2Buttons.py @@ -41,8 +41,6 @@ #================================================================================== # Example 7 -from __future__ import print_function -import qwiic_i2c import qwiic_button import time import sys @@ -68,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: 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 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, \