-
Notifications
You must be signed in to change notification settings - Fork 0
/
SensorGraphics.py
72 lines (49 loc) · 1.65 KB
/
SensorGraphics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import serial
import Tkinter
import time
import sys
import pygame
###################### SET UP PYGAME #######################
pygame.init()
window = pygame.display.set_mode((640,480))
# First, clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.
window.fill((255,255,255))
# Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
###################### SET UP SERIAL BAUD RATE ####################
usbport = 'COM4'
ser = serial.Serial(usbport, 9600, timeout=1)
###################### INITIALIZE VARIABLES #######################
radius = 0
deltaR =1
distString= ""
dist =- 0
# -------- Main Program Loop -----------
while not done:
#---------------------- GET THE DISTANCE FROM THE ARDUINO ------------------
distString =""
for line in ser.readline():
if line.isdigit():
distString+=line
if distString.isdigit():
dist = float(distString)
# --- Main event loop -------------------------------
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT:
print("User asked to quit.")
pygame.quit()
done = True
# --- Game logic should go here
radius = dist*3
print dist
# --- Drawing code should go here
if not done:
window.fill((255,255,255))
pygame.draw.circle(window, (255,0,255), (310, 230), (int)(radius))
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 60 frames per second
clock.tick(50)