Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/qwiic_button_ex1_buttonPress.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#==================================================================================
# Example 1

from __future__ import print_function
import qwiic_button
import time
import sys
Expand All @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions examples/qwiic_button_ex2_LEDon.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#==================================================================================
# Example 2

from __future__ import print_function
import qwiic_button
import time
import sys
Expand All @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions examples/qwiic_button_ex3_LEDconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#==================================================================================
# Example 3

from __future__ import print_function
import qwiic_button
import time
import sys
Expand All @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions examples/qwiic_button_ex4_queueUsage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#==================================================================================
# Example 4

from __future__ import print_function
import qwiic_button
import time
import sys
Expand All @@ -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:
Expand Down
11 changes: 5 additions & 6 deletions examples/qwiic_button_ex5_popQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#==================================================================================
# Example 5

from __future__ import print_function
import qwiic_button
import time
import sys
Expand All @@ -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:
Expand Down
30 changes: 16 additions & 14 deletions examples/qwiic_button_ex6_changeI2CAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", \
Expand All @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions examples/qwiic_button_ex7_2Buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#==================================================================================
# Example 7

from __future__ import print_function
import qwiic_i2c
import qwiic_button
import time
import sys
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion qwiic_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"""
#-----------------------------------------------------------------------------------

import math
import qwiic_i2c

# Define the device name and I2C addresses. These are set in the class definition
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down