Skip to content

Commit 1da983b

Browse files
v0.0.2
1 parent 2b0620d commit 1da983b

File tree

15 files changed

+77
-460
lines changed

15 files changed

+77
-460
lines changed

.readthedocs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
python:
2+
version: 3
3+
install:
4+
- requirements: docs/requirements.txt
5+
setup_py_install: true

README.md

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ Qwiic_Relay_Py
55
<img src="https://www.python.org/static/community_logos/python-logo-master-v3-TM.png" width=240>
66
</p>
77
<p align="center">
8-
<a href="https://pypi.org/project/sparkfun-top-phat-button/" alt="Package">
9-
<img src="https://img.shields.io/pypi/pyversions/sparkfun-top-phat-button.svg" /></a>
10-
<a href="https://github.com/sparkfun/Top_pHAT_Button_Py/issues" alt="Issues">
11-
<img src="https://img.shields.io/github/issues/sparkfun/Top_pHAT_Button_Py.svg" /></a>
12-
<a href="https://sparkfun-top-phat-button.readthedocs.io/en/latest/?" alt="Documentation">
13-
<img src="https://readthedocs.org/projects/sparkfun-top-phat-button/badge/?version=latest&style=flat" /></a>
14-
<a href="https://github.com/sparkfun/Top_pHAT_Button_Py/blob/master/LICENSE" alt="License">
8+
<a href="https://pypi.org/project/sparkfun-qwiic-relay/" alt="Package">
9+
<img src="https://img.shields.io/pypi/pyversions/sparkfun-qwiic-relay.svg" /></a>
10+
<a href="https://github.com/sparkfun/Qwiic_Relay_Py/issues" alt="Issues">
11+
<img src="https://img.shields.io/github/issues/sparkfun/Qwiic_Relay_Py.svg" /></a>
12+
<a href="https://sparkfun-qwiic-relay.readthedocs.io/en/latest/?" alt="Documentation">
13+
<img src="https://readthedocs.org/projects/sparkfun-qwiic-relay/badge/?version=latest&style=flat" /></a>
14+
<a href="https://github.com/sparkfun/Qwiic_Relay_Py/blob/master/LICENSE" alt="License">
1515
<img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
1616
<a href="https://twitter.com/intent/follow?screen_name=sparkfun">
1717
<img src="https://img.shields.io/twitter/follow/sparkfun.svg?style=social&logo=twitter"
1818
alt="follow on Twitter"></a>
1919

2020
</p>
2121

22-
<img src="https://cdn.sparkfun.com/assets/parts/1/5/0/0/3/16301-SparkFun_Top_pHAT_for_Raspberry_Pi-01.jpg" align="right" width=300 alt="SparkFun Top pHAT">
22+
<img src="https://cdn.sparkfun.com/assets/parts/1/5/7/5/4/16833-SparkFun_Qwiic_Quad_Solid_State_Relay_Kit-01.jpg" align="right" width=300 alt="SparkFun Qwiic Solid State Relay">
2323

2424
Python module for the Qwiic Relays, Listed below
2525
* [SparkFun Qwiic Single Relay](https://www.sparkfun.com/products/15093)
@@ -93,57 +93,49 @@ See the examples directory for more detailed use examples.
9393

9494
```python
9595
from __future__ import print_function
96-
import top_phat_button
96+
import qwiic_relay
9797
import time
9898
import sys
9999

100-
myButtons = top_phat_button.ToppHATButton()
100+
myRelays = qwiic_relay.QwiicRelay()
101101

102102
def runExample():
103103

104-
print("\nSparkFun Top pHAT Button Example 1\n")
104+
print("\nSparkFun Qwiic Relay Example 1\n")
105105

106-
if myButtons.is_connected() == False:
107-
print("The Top pHAT Button device isn't connected to the system. Please check your connection", \
106+
if myRelays.begin() == False:
107+
print("The Qwiic Relay isn't connected to the system. Please check your connection", \
108108
file=sys.stderr)
109109
return
110110

111-
myButtons.pressed_interrupt_enable = False
112-
myButtons.clicked_interrupt_enable = False
111+
#Turn on relays one and three
112+
myRelays.set_relay_on(1)
113+
myRelays.set_relay_on(3)
114+
time.sleep(1)
113115

114-
while True:
115-
myButtons.button_pressed #These functions must be called to update button variables to their latest setting
116-
myButtons.button_clicked #These functions must be called to update button variables to their latest setting
117-
if myButtons.a_pressed == True:
118-
print("A Pressed")
119-
if myButtons.a_clicked == True:
120-
print("A Released")
121-
if myButtons.b_pressed == True:
122-
print("B Pressed")
123-
if myButtons.b_clicked == True:
124-
print("B Released")
125-
if myButtons.up_pressed == True:
126-
print("Up Pressed")
127-
if myButtons.up_clicked == True:
128-
print("Up Released")
129-
if myButtons.down_pressed == True:
130-
print("Down Pressed")
131-
if myButtons.down_clicked == True:
132-
print("Down Released")
133-
if myButtons.left_pressed == True:
134-
print("Left Pressed")
135-
if myButtons.left_clicked == True:
136-
print("Left Released")
137-
if myButtons.right_pressed == True:
138-
print("Right Pressed")
139-
if myButtons.right_clicked == True:
140-
print("Right Released")
141-
if myButtons.center_pressed == True:
142-
print("Center Pressed")
143-
if myButtons.center_clicked == True:
144-
print("Center Released")
116+
#Print the status of all relays
117+
for relayNum in range(4):
118+
current_status = None
119+
if myRelays.get_relay_state(relayNum) is True:
120+
current_status = "On"
121+
else:
122+
current_status = "Off"
123+
print("Status 1: " + current_status + "\n")
124+
125+
#Turn off 1 and 3, turn on 2 and 4
126+
myRelays.set_relay_off(1)
127+
myRelays.set_relay_on(2)
128+
myRelays.set_relay_off(3)
129+
myRelays.set_relay_on(4)
130+
time.sleep(1)
131+
132+
133+
#Turn all relays on, then turn them all off
134+
myRelays.set_all_relays_on()
135+
time.sleep(1)
136+
137+
myRelays.set_all_relays_off()
145138

146-
time.sleep(.1)
147139

148140

149141
if __name__ == '__main__':
@@ -152,7 +144,6 @@ if __name__ == '__main__':
152144
except (KeyboardInterrupt, SystemExit) as exErr:
153145
print("\nEnding Example 1")
154146
sys.exit(0)
155-
156147
```
157148
<p align="center">
158149
<img src="https://cdn.sparkfun.com/assets/custom_pages/3/3/4/dark-logo-red-flame.png" alt="SparkFun - Start Something">

0 commit comments

Comments
 (0)