Skip to content

Commit c997ffc

Browse files
committed
Update to pythonic naming convention
Changed all function, variable, and object names from camel case to underscores
1 parent ccf551c commit c997ffc

8 files changed

+264
-267
lines changed

examples/qwiic_button_ex1_buttonPress.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@
4444
import time
4545
import sys
4646

47-
def runExample():
47+
def run_example():
4848

4949
print("\nSparkFun Qwiic Button Example 1")
50-
myButton = qwiic_button.QwiicButton()
50+
my_button = qwiic_button.Qwiic_Button()
5151

52-
if myButton.begin() == False:
52+
if my_button.begin() == False:
5353
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
5454
file=sys.stderr)
5555
return
5656
print("\nButton ready!")
5757

5858
while True:
5959

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

6363
else:
@@ -67,7 +67,7 @@ def runExample():
6767

6868
if __name__ == '__main__':
6969
try:
70-
runExample()
70+
run_example()
7171
except (KeyboardInterrupt, SystemExit) as exErr:
7272
print("\nEnding Example 1")
7373
sys.exit(0)

examples/qwiic_button_ex2_LEDon.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646

4747
brightness = 100
4848

49-
def runExample():
49+
def run_example():
5050

5151
print("\nSparkFun Qwiic Button Example 2")
52-
myButton = qwiic_button.QwiicButton()
52+
my_button = qwiic_button.Qwiic_Button()
5353

54-
if myButton.begin() == False:
54+
if my_button.begin() == False:
5555
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
5656
file=sys.stderr)
5757
return
@@ -60,19 +60,19 @@ def runExample():
6060

6161
while True:
6262

63-
if myButton.isButtonPressed() == True:
63+
if my_button.is_button_pressed() == True:
6464
print("\nThe button is pressed!")
65-
myButton.LEDon(brightness)
65+
my_button.LED_on(brightness)
6666

6767
else:
6868
print("\nThe button is not pressed.")
69-
myButton.LEDoff()
69+
my_button.LED_off()
7070

7171
time.sleep(0.02)
7272

7373
if __name__ == '__main__':
7474
try:
75-
runExample()
75+
run_example()
7676
except (KeyboardInterrupt, SystemExit) as exErr:
7777
print("\nEnding Example 2")
7878
sys.exit(0)

examples/qwiic_button_ex3_LEDconfig.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,39 +45,39 @@
4545
import sys
4646

4747
brightness = 250 # The maximum brightness of the pulsing LED. Can be between 0 and 255
48-
cycleTime = 1000 # The total time for the pulse to take. Set to a bigger number for a slower pulse or a smaller number for a faster pulse
49-
offTime = 200 # The total time to stay off between pulses. Set to 0 to be pulsing continuously.
48+
cycle_time = 1000 # The total time for the pulse to take. Set to a bigger number for a slower pulse or a smaller number for a faster pulse
49+
off_time = 200 # The total time to stay off between pulses. Set to 0 to be pulsing continuously.
5050

51-
def runExample():
51+
def run_example():
5252

5353
print("\nSparkFun Qwiic Button Example 3")
54-
myButton = qwiic_button.QwiicButton()
54+
my_button = qwiic_button.Qwiic_Button()
5555

56-
if myButton.begin() == False:
56+
if my_button.begin() == False:
5757
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
5858
file=sys.stderr)
5959
return
6060

6161
print("\nButton ready!")
6262

63-
myButton.LEDoff()
63+
my_button.LED_off()
6464

6565
while True:
6666

67-
if myButton.isButtonPressed() == True:
67+
if my_button.is_button_pressed() == True:
6868

6969
print("\nThe button is pressed!")
70-
myButton.LEDconfig(brightness, cycleTime, offTime)
70+
my_button.LED_config(brightness, cycle_time, off_time)
7171

7272
else:
7373
print("\nThe button is not pressed.")
74-
myButton.LEDoff()
74+
my_button.LED_off()
7575

7676
time.sleep(0.02) # Let's not hammer too hard on the I2C bus
7777

7878
if __name__ == '__main__':
7979
try:
80-
runExample()
80+
run_example()
8181
except (KeyboardInterrupt, SystemExit) as exErr:
8282
print("\nEnding Example 3")
8383
sys.exit(0)

examples/qwiic_button_ex4_queueUsage.py

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

46-
def runExample():
46+
def run_example():
4747

4848
print("\nSparkFun Qwiic Button Example 4")
49-
myButton = qwiic_button.QwiicButton()
49+
my_button = qwiic_button.Qwiic_Button()
5050

51-
if myButton.begin() == False:
51+
if my_button.begin() == False:
5252
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
5353
file=sys.stderr)
5454
return
@@ -58,28 +58,28 @@ def runExample():
5858
while True:
5959

6060
# If the queue of pressed events is not empty
61-
if myButton.isPressedQueueEmpty() == False:
61+
if my_button.is_pressed_queue_empty() == False:
6262
# Then print the time since the last and first button press
63-
print("\n" + str(myButton.timeSinceLastPress() / 1000.0) + "s since he button was last pressed ")
64-
print(str(myButton.timeSinceFirstPress() / 1000.0) +"s since the button was first pressed ")
63+
print("\n" + str(my_button.time_since_last_press() / 1000.0) + "s since he button was last pressed ")
64+
print(str(my_button.time_since_first_press() / 1000.0) +"s since the button was first pressed ")
6565
# If the queue is empty
6666
else:
67-
print("\nButtonPressed Queue is empty! ")
67+
print("\nButton Pressed Queue is empty! ")
6868

6969
# If the queue of clicked events is not empty
70-
if myButton.isClickedQueueEmpty() == False:
70+
if my_button.is_clicked_queue_empty() == False:
7171
# Then print the time since the last and first button click
72-
print("\n" + str(myButton.timeSinceLastClick() / 1000.0) + "s since the button was last clicked ")
73-
print(str(myButton.timeSinceFirstClick() / 1000.0) + "s since the button was first clicked")
72+
print("\n" + str(my_button.time_since_last_click() / 1000.0) + "s since the button was last clicked ")
73+
print(str(my_button.time_since_first_click() / 1000.0) + "s since the button was first clicked")
7474
# If the queue is empty
7575
else:
76-
print("\nButtonClicked Queue is empty!")
76+
print("\nButton Clicked Queue is empty!")
7777

7878
time.sleep(0.02) # Let's not hammer too hard on the I2C bus
7979

8080
if __name__ == '__main__':
8181
try:
82-
runExample()
82+
run_example()
8383
except (KeyboardInterrupt, SystemExit) as exErr:
8484
print("\nEnding Example 4")
8585
sys.exit(0)

examples/qwiic_button_ex5_popQueue.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
import time
4444
import sys
4545

46-
def runExample():
46+
def run_example():
4747

4848
print("\nSparkFun Qwiic Button Example 5")
49-
myButton = qwiic_button.QwiicButton()
49+
my_button = qwiic_button.Qwiic_Button()
5050

51-
if myButton.begin() == False:
51+
if my_button.begin() == False:
5252
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
5353
file=sys.stderr)
5454
return
@@ -61,18 +61,18 @@ def runExample():
6161
val = raw_input("Type 'c' to pop a value from the clicked queue: ")
6262
# If the character is c or C, then pop a value off of the clicked queue
6363
if val == "c" or val == "C":
64-
print("\nPopped ClickedQueue! The first value of clicked queue was: ")
65-
print(str(myButton.popClickedQueue() / 1000.0))
64+
print("\nPopped Clicked Queue! The first value of clicked queue was: ")
65+
print(str(my_button.pop_clicked_queue() / 1000.0))
6666
# If the character is p or P, then pop a value off of the pressed queue
6767
if val == "p" or val == "P":
68-
print("\nPopped PressedQueue!")
69-
print(str(myButton.popClickedQueue() / 1000.0))
68+
print("\nPopped Pressed Queue!")
69+
print(str(my_button.pop_clicked_queue() / 1000.0))
7070

7171
time.sleep(0.02) # Let's not hammer too hard on the I2C bus
7272

7373
if __name__ == '__main__':
7474
try:
75-
runExample()
75+
run_example()
7676
except (KeyboardInterrupt, SystemExit) as exErr:
7777
print("\nEnding Example 5")
7878
sys.exit(0)

examples/qwiic_button_ex6_changeI2CAddress.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
import time
4646
import sys
4747

48-
def runExample():
48+
def run_example():
4949

5050
print("\nSparkFun Qwiic Button Example 6")
51-
myButton = qwiic_button.QwiicButton()
51+
my_button = qwiic_button.Qwiic_Button()
5252

53-
if myButton.begin() == False:
53+
if my_button.begin() == False:
5454
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
5555
file=sys.stderr)
5656
return
@@ -61,19 +61,19 @@ def runExample():
6161
print("\nDon't use the 0x prefix. For instance, if you wanted to")
6262
print("\nchange the address to 0x5B, you would type 5B and hit enter.")
6363

64-
newAddress = raw_input("\nNew Address: ")
65-
newAddress = int(newAddress, 16)
64+
new_address = raw_input("\nNew Address: ")
65+
new_address = int(new_address, 16)
6666

6767
# Check if the user entered a valid address
68-
if newAddress > 0x08 and newAddress < 0x77:
68+
if new_address > 0x08 and new_address < 0x77:
6969
print("\nCharacters received and new address valid!")
7070
print("\nAttempting to set Qwiic Button address...")
7171

72-
myButton.setI2Caddress(newAddress)
72+
my_button.set_I2C_address(new_address)
7373
print("\nAddress successfully changed!")
7474
# Check that the Qwiic Button acknowledges on the new address
7575
time.sleep(0.02)
76-
if myButton.begin() == False:
76+
if my_button.begin() == False:
7777
print("\nThe Qwiic Button isn't connected to the system. Please check your connection", \
7878
file=sys.stderr)
7979

@@ -85,7 +85,7 @@ def runExample():
8585

8686
if __name__ == '__main__':
8787
try:
88-
runExample()
88+
run_example()
8989
except (KeyboardInterrupt, SystemExit) as exErr:
9090
print("\nEnding Example 6")
9191
sys.exit(0)

examples/qwiic_button_ex7_2Buttons.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@
4747
import time
4848
import sys
4949

50-
def runExample():
50+
def run_example():
5151

5252
print("\nSparkFun Qwiic Button Example 7")
53-
myButton1 = qwiic_button.QwiicButton()
54-
myButton2 = qwiic_button.QwiicButton(0x5B)
53+
my_button1 = qwiic_button.Qwiic_Button()
54+
my_button2 = qwiic_button.Qwiic_Button(0x5B)
5555

56-
if myButton1.begin() == False:
56+
if my_button1.begin() == False:
5757
print("\nThe Qwiic Button 1 isn't connected to the system. Please check your connection", \
5858
file=sys.stderr)
5959
return
60-
if myButton2.begin() == False:
60+
if my_button2.begin() == False:
6161
print("\nThe Qwiic Button 2 isn't connected to the system. Please check your connection", \
6262
file=sys.stderr)
6363
return
@@ -67,18 +67,18 @@ def runExample():
6767
while 1:
6868

6969
# Check if button 1 is pressed
70-
if myButton1.isButtonPressed() == True:
70+
if my_button1.is_button_pressed() == True:
7171
print("\nButton 1 is pressed!")
7272

7373
# Check if button2 is pressed
74-
if myButton2.isButtonPressed() == True:
74+
if my_button2.is_button_pressed() == True:
7575
print("\nButton 2 is pressed!")
7676

7777
time.sleep(0.02) # Don't hammer too hard on the I2C bus
7878

7979
if __name__ == '__main__':
8080
try:
81-
runExample()
81+
run_example()
8282
except (KeyboardInterrupt, SystemExit) as exErr:
8383
print("\nEnding Example 7")
8484
sys.exit(0)

0 commit comments

Comments
 (0)