logger.info("DISTANCE: %s", connection.read_distance()) if randomDirection() == 0: turnClockwise() else: turnCounterClockwise() elif bumpLeft: connection.stop() logger.info("DISTANCE: %s", connection.read_distance()) turnClockwise() elif bumpRight: connection.stop() logger.info("DISTANCE: %s", connection.read_distance()) turnCounterClockwise() connection = state_interface.Interface() connection.set_full() while True: cleanDetect = connection.read_button(connection.getClean()) wheelDrop, bumpLeft, bumpRight = connection.bump_wheel_drop() cliff = connection.read_cliff() if not MOVING and not wheelDrop and cliff == 0 and cleanDetect: logger.info('BUTTON') myThread = threading.Thread(target=cantStopWontStop) MOVING = True myThread.start() elif MOVING and cleanDetect: logger.info('BUTTON') MOVING = False connection.stop()
import serial from time import sleep import struct import state_interface c = state_interface.Interface() sleep(0.015) while True: sleep(0.015) c.drive(200, -1) sleep(0.015) data = c.read_button(1) #data = c.read(1) print data byte = struct.unpack('B', data)[0] if bool(byte & 0x01): print "Clean this dick." break