3939#==================================================================================
4040# Example 5
4141
42- from __future__ import print_function
43- import qwiic_i2c
4442import qwiic_button
4543import time
4644import 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+
4849def run_example ():
4950
5051 print ("\n SparkFun 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 ("\n The Qwiic Button isn't connected to the system. Please check your connection" , \
@@ -57,31 +58,32 @@ def run_example():
5758
5859 print ("\n Button ready!" )
5960
60- print ("\n Enter a new I2C address for the Qwiic Button to use." )
61- print ("\n Don't use the 0x prefix. For instance, if you wanted to" )
62- print ("\n change 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 ( " \n New 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 ("\n Characters received and new address valid!" )
70- print ("\n Attempting 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 ("\n Address 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 ("\n The 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 ("\n Button acknowledged on new address!" )
83+ print ("Button acknowledged on new address!" )
8284
8385 else :
84- print ("\n Address entered not a valid I2C address" )
86+ print ("Address entered not a valid I2C address" )
8587
8688if __name__ == '__main__' :
8789 try :
0 commit comments