Skip to content

Commit 7568f1f

Browse files
committed
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
1 parent f2848ee commit 7568f1f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/qwiic_button_ex6_changeI2CAddress.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@
4343
import time
4444
import sys
4545

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

4851
print("\nSparkFun Qwiic Button Example 6")
49-
my_button = qwiic_button.QwiicButton()
52+
my_button = qwiic_button.QwiicButton(currentAddress)
5053

5154
if my_button.begin() == False:
5255
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
@@ -58,14 +61,15 @@ def run_example():
5861
print("\nEnter a new I2C address for the Qwiic Button to use.")
5962
print("\nDon't use the 0x prefix. For instance, if you wanted to")
6063
print("\nchange the address to 0x5B, you would type 5B and hit enter.")
64+
print("Any address from 0x08 to 0x77 works.")
6165

6266
new_address = input("\nNew Address: ")
6367
new_address = int(new_address, 16)
6468

6569
# Check if the user entered a valid address
66-
if new_address > 0x08 and new_address < 0x77:
6770
print("\nCharacters received and new address valid!")
6871
print("\nAttempting to set Qwiic Button address...")
72+
if new_address >= 0x08 and new_address <= 0x77:
6973

7074
my_button.set_I2C_address(new_address)
7175
print("\nAddress successfully changed!")

0 commit comments

Comments
 (0)