Esempio n. 1
0
def main():
    #This is how you should connect to your spark. This code must execute
    #before the raspberry pi can talk to the spark hat.

    addr = "tcp://raspberrypi.local:4567"
    comm = NET_ZMQ_Comm()
    try:
        comm.open(addr)
    except:
        print "Error connecting to Spark"
        sys.exit()

    spark = Spark_Drive(comm)
    drive_loop(spark)  #call the never ending "drive_loop" function
Esempio n. 2
0
def main():
    addr = raw_input(
        "Address of target (tcp://its.ip.add.ress:port) or hit enter for local USB:"
    )
    if addr == "-":
        addr = "tcp://raspberrypi.local:4567"
    if addr == "":
        comm = HID_Comm()
        try:
            comm.open()
        except IOError, ex:
            print "Spark not found:", ex
            sys.exit()
    else:
        comm = NET_ZMQ_Comm()
        try:
            comm.open(addr)
        except:
            print "Error connecting to Spark"
            sys.exit()

    spark = Spark_Drive(comm)
    us_loop(spark)


def us_loop(spark):
    while (1):
        print(65535 - spark.get_ultrasonic(1))
        print(65535 - spark.get_ultrasonic(2))
        time.sleep(1)