forked from Telos4/RoboRally
added error message if no i2c devices are found
This commit is contained in:
parent
2fb69de9c5
commit
79f4fcc032
|
@ -1,4 +1,5 @@
|
|||
import machine
|
||||
import sys
|
||||
from machine import I2C, Pin
|
||||
|
||||
import d1motor
|
||||
|
@ -13,14 +14,19 @@ class Robot:
|
|||
d1 = Pin(5)
|
||||
d2 = Pin(4)
|
||||
i2c = I2C(scl=d1, sda=d2)
|
||||
i2c_addr = i2c.scan()[0]
|
||||
print("i2c scan = {}".format(i2c_addr))
|
||||
print("setting up motors ...")
|
||||
self.m1 = d1motor.Motor(0, i2c, address=i2c_addr)
|
||||
self.m2 = d1motor.Motor(1, i2c, address=i2c_addr)
|
||||
self.m1.speed(0)
|
||||
self.m2.speed(0)
|
||||
print("motor setup complete!")
|
||||
i2c_scan = i2c.scan()
|
||||
if len(i2c_scan) > 0:
|
||||
i2c_addr = i2c_scan[0]
|
||||
print("i2c scan = {}".format(i2c_addr))
|
||||
print("setting up motors ...")
|
||||
self.m1 = d1motor.Motor(0, i2c, address=i2c_addr)
|
||||
self.m2 = d1motor.Motor(1, i2c, address=i2c_addr)
|
||||
self.m1.speed(0)
|
||||
self.m2.speed(0)
|
||||
print("motor setup complete!")
|
||||
else:
|
||||
print("error: no i2c interfaces found!")
|
||||
sys.exit(1)
|
||||
|
||||
ip = my_ip[0]
|
||||
# setup socket for remote control
|
||||
|
|
Loading…
Reference in New Issue
Block a user