import sys, pygame, math
from pygame.locals import *
import time, serial

ser = serial.Serial(port='/dev/ttyUSB0',baudrate=9600,parity=serial.PARITY_ODD)

# set up a bunch of constants
WHITE    = (255, 255, 255)
BLACK    = (  0,   0,   0)
RED      = (255,   0,   0)

BGCOLOR = WHITE

WINDOWWIDTH = 600	
WINDOWHEIGHT = 600 

pygame.init()
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('Move Circle')
FPS = 300
x=300
y=300
while True:
	


	'''for event in pygame.event.get():
		if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
			pygame.quit()	            
			sys.exit()'''
	while ser.inWaiting()>0:
		data = ser.read()
	if data=='a':
		x+= 2
	elif data== 'c':
		x-= 2
	elif data=='e':
		x+= 1
	elif data== 'd':
		x-= 1
	
	
	DISPLAYSURF.fill(BGCOLOR)
	
	pygame.draw.circle(DISPLAYSURF, RED,(x,y), 40)
	

	pygame.display.update()
	FPSCLOCK.tick(FPS)

