def on_message(self, message): msg = json.loads(message) # Arrow key input for motors if (msg.has_key('Velocity')): velocities = msg['Velocity'] arduino_com.controlMotors(velocities[0], velocities[1]) # Slider used to adjust throttle for all motors if (msg.has_key('Thr')): self.throttle = msg['Thr'] / 256.0 # Tilt used to adjust camera position if (msg.has_key('Tilt')): orientation = msg['Tilt'] arduino_com.v_servo_write(orientation[1]) arduino_com.h_servo_write(orientation[0]) if (msg.has_key('Bitrate')): os.system('/home/pi/rover/start-everything.sh restartcamera ' + str(msg['Bitrate'])) if (msg.has_key('RGB')): color = msg['RGB'] if color[3] == True: arduino_com.led_rainbowfy(color[6]) else: arduino_com.led_color(color[0], color[1], color[2]) if color[4] == "Solid" : arduino_com.led_solid() elif color[4] == "Chasers" : arduino_com.led_chasers(float(color[5])) elif color[4] == "Rainbow" : arduino_com.led_rainbow(float(color[5]))
import arduino_com import time arduino_com.init(); while(1): '''print("off") arduino_com.led_off(); time.sleep(1) print("solid") for x in range(0, 255 , 10 ): arduino_com.led_solid(x, 0, 255 - x) time.sleep(0.1) print(x) print("rainbow") for x in range(0, 20): arduino_com.led_rainbow(25 - x) time.sleep(0.3) time.sleep(5)''' print("chasers") arduino_com.led_chasers(0, 128, 0, -5) time.sleep(5)
# Program starts here #----------------------------------------------------- if __name__ == '__main__': print('Entered main') # Start the websocket application = tornado.web.Application([ (r'/keysocket', KeyPressHandler), (r'/(.*)', tornado.web.StaticFileHandler, { 'path': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'www'), 'default_filename': 'index.html' }) ], debug = True) # Set up connection to Arduino on the USB port # arduino_serial = serial.Serial('/dev/ttyACM0', 115200); # Time in between thread polling polling_time = 0.3 #conn = websocket_connect('ws://aftersomemath.com:8888/rover', on_message_callback = data_received) print('Starting port') application.listen(8080) print('Started port') print('Started Arduino Com') arduino_com.init() arduino_com.led_chasers(10) try: tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: cleanup() finally: cleanup()