-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxl9535_relay_circuits.py
44 lines (34 loc) · 973 Bytes
/
xl9535_relay_circuits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# SPDX-FileCopyrightText: 2024 Mike Causer <https://github.com/mcauser>
# SPDX-License-Identifier: MIT
"""
MicroPython XL9535 KxV5 Relay
https://github.com/mcauser/micropython-xl9535-kxv5-relay
"""
import xl9535_relay
from machine import I2C, Pin
i2c = I2C(0)
board = xl9535_relay.XL9535_KXV5(i2c, 0x20)
board.init()
# turn all relays on
board.relays(0xFFFF)
# turn all circuits on
board.circuits(0xFFFF)
# turn circuit A0 off
board.circuit(0, False)
# relay A0 switches off
# turn circuit A1 off
board.circuit(1, False)
# relay A1 switches off
# what relays are on?
board.relays()
# 65535
# 65535 == 0b_1111_1111_1111_1111 == 0xFFFF
# all of them are on
# what circuits are on?
board.circuits()
# 65532
# 65532 == 0b_1111_1111_1111_1100 == 0xFFFC
# circuits A0 and A1 off, the rest on
# having two independent controls for each relay means one
# can store the desired relay state and the other can be used
# as a toggle without affecting the desired relay state