Commit 9f09b5c2 authored by Ivan Tyagov's avatar Ivan Tyagov

Wrap communication over IC2.

parent 663790fe
...@@ -86,18 +86,20 @@ RELAY_MAP = {0: 0x00, ...@@ -86,18 +86,20 @@ RELAY_MAP = {0: 0x00,
4: 0x128} 4: 0x128}
def sendI2Ccommand(code): def sendI2Ccommand(code):
# init I2C
i2c.init("/dev/i2c-1")
i2c.open(0x58)
try: try:
i2c.write([0x10, code]) i2c.write([0x10, code])
except: except:
print("Failed co sent command.") print("Failed co sent command.")
i2c.close()
motor_on = False motor_on = False
valve_on = False valve_on = False
# init I2C
i2c.init("/dev/i2c-1")
i2c.open(0x58)
# stop all # stop all
sendI2Ccommand(0x00) sendI2Ccommand(0x00)
...@@ -113,8 +115,8 @@ while 1: ...@@ -113,8 +115,8 @@ while 1:
print("Invalid input") print("Invalid input")
if command == 1: if command == 1:
# startmotor relay # start motor relay
sendI2Ccommand(0x0001) sendI2Ccommand(0x01)
elif command == 2: elif command == 2:
# toggle air valve relay # toggle air valve relay
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment