Skip to content

Commit d19372b

Browse files
committed
Update example formatting
Don't need so many newlines Slow down print loops to 0.1s delays
1 parent 7568f1f commit d19372b

7 files changed

+34
-31
lines changed

examples/qwiic_button_ex1_buttonPress.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ def run_example():
5757
while True:
5858

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

6262
else:
63-
print("\nThe button is not pressed!")
63+
print("The button is not pressed!")
6464

65-
time.sleep(0.02)
65+
time.sleep(0.1)
6666

6767
if __name__ == '__main__':
6868
try:

examples/qwiic_button_ex2_LEDon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ def run_example():
6060
while True:
6161

6262
if my_button.is_button_pressed() == True:
63-
print("\nThe button is pressed!")
63+
print("The button is pressed!")
6464
my_button.LED_on(brightness)
6565

6666
else:
67-
print("\nThe button is not pressed.")
67+
print("The button is not pressed.")
6868
my_button.LED_off()
6969

70-
time.sleep(0.02)
70+
time.sleep(0.1)
7171

7272
if __name__ == '__main__':
7373
try:

examples/qwiic_button_ex3_LEDconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def run_example():
6565

6666
if my_button.is_button_pressed() == True:
6767

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

7171
else:
72-
print("\nThe button is not pressed.")
72+
print("The button is not pressed.")
7373
my_button.LED_off()
7474

75-
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
7676

7777
if __name__ == '__main__':
7878
try:

examples/qwiic_button_ex4_queueUsage.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,25 @@ def run_example():
5959
# If the queue of pressed events is not empty
6060
if my_button.is_pressed_queue_empty() == False:
6161
# Then print the time since the last and first button press
62-
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 ")
6363
print(str(my_button.time_since_first_press() / 1000.0) +"s since the button was first pressed ")
6464
# If the queue is empty
6565
else:
66-
print("\nButton Pressed Queue is empty! ")
66+
print("Button Pressed Queue is empty! ")
6767

6868
# If the queue of clicked events is not empty
6969
if my_button.is_clicked_queue_empty() == False:
7070
# Then print the time since the last and first button click
71-
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 ")
7272
print(str(my_button.time_since_first_click() / 1000.0) + "s since the button was first clicked")
7373
# If the queue is empty
7474
else:
75-
print("\nButton Clicked Queue is empty!")
75+
print("Button Clicked Queue is empty!")
7676

77-
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
7881

7982
if __name__ == '__main__':
8083
try:

examples/qwiic_button_ex5_popQueue.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ def run_example():
5656

5757
while True:
5858

59-
print("\nType 'p' to pop a value from the pressed queue.")
59+
print("Type 'p' to pop a value from the pressed queue.")
6060
val = input("Type 'c' to pop a value from the clicked queue: ")
6161
# If the character is c or C, then pop a value off of the clicked queue
6262
if val == "c" or val == "C":
63-
print("\nPopped Clicked Queue! The first value of clicked queue was: ")
63+
print("Popped Clicked Queue! The first value of clicked queue was: ")
6464
print(str(my_button.pop_clicked_queue() / 1000.0))
6565
# If the character is p or P, then pop a value off of the pressed queue
6666
if val == "p" or val == "P":
67-
print("\nPopped Pressed Queue!")
67+
print("Popped Pressed Queue!")
6868
print(str(my_button.pop_clicked_queue() / 1000.0))
6969

70-
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
7171

7272
if __name__ == '__main__':
7373
try:

examples/qwiic_button_ex6_changeI2CAddress.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,32 @@ def run_example():
5858

5959
print("\nButton ready!")
6060

61-
print("\nEnter a new I2C address for the Qwiic Button to use.")
62-
print("\nDon't use the 0x prefix. For instance, if you wanted to")
63-
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.")
6462
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.")
6565

66-
new_address = input("\nNew Address: ")
66+
new_address = input("New Address: ")
6767
new_address = int(new_address, 16)
6868

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

7474
my_button.set_I2C_address(new_address)
75-
print("\nAddress successfully changed!")
75+
print("Address successfully changed!")
7676
# Check that the Qwiic Button acknowledges on the new address
7777
time.sleep(0.02)
7878
if my_button.begin() == False:
79-
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", \
8080
file=sys.stderr)
8181

8282
else:
83-
print("\nButton acknowledged on new address!")
83+
print("Button acknowledged on new address!")
8484

8585
else:
86-
print("\nAddress entered not a valid I2C address")
86+
print("Address entered not a valid I2C address")
8787

8888
if __name__ == '__main__':
8989
try:

examples/qwiic_button_ex7_2Buttons.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ def run_example():
6666

6767
# Check if button 1 is pressed
6868
if my_button1.is_button_pressed() == True:
69-
print("\nButton 1 is pressed!")
69+
print("Button 1 is pressed!")
7070

7171
# Check if button2 is pressed
7272
if my_button2.is_button_pressed() == True:
73-
print("\nButton 2 is pressed!")
73+
print("Button 2 is pressed!")
7474

75-
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
7676

7777
if __name__ == '__main__':
7878
try:

0 commit comments

Comments
 (0)