uas_arduino

Touchscreen GUI

Jul 16th, 2015
219
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import pygame
  4. import serial
  5. from pygame.locals import *
  6. from time import sleep
  7. from random import randint
  8. import sys
  9. points = []
  10. size = 32
  11.  
  12. if(len(sys.argv) != 3):
  13.   print "Usage: %s serial_port baud_rate\n" % sys.argv[0];
  14.   exit(1)
  15.  
  16.  
  17. serialPort = sys.argv[1]
  18. baudRate = int(sys.argv[2])
  19.  
  20. for i in range(0, size):
  21.   points.append((0, 0))
  22.  
  23. s = serial.Serial(serialPort, baudRate);
  24. s.flushInput()
  25. s.flush()
  26.  
  27. def main():
  28.   pygame.init()
  29.   screen = pygame.display.set_mode((256, 256))
  30.   background = pygame.Surface(screen.get_size())
  31.   background = background.convert()
  32.   background.fill((255, 255, 255))
  33.  
  34.   # Blit everything to the screen
  35.   screen.blit(background, (0, 0))
  36.   pygame.display.flip()
  37.  
  38.  
  39.  
  40.   # Event loop
  41.   while 1:
  42.     for event in pygame.event.get():
  43.       if event.type == QUIT:
  44.         return
  45.    
  46.     l = points.pop(0)
  47.     n = (ord(s.read()) + 1, ord(s.read()) + 1)
  48.     print "%d %d\n" % (n[0], n[1])
  49.     points.append(n)
  50.  
  51.     screen.set_at((l[0], l[1]), (255, 255, 255))
  52.  
  53.     for i in points:
  54.       screen.set_at((i[0], i[1]), (0,0,0))
  55.  
  56.     #screen.blit(background, (0, 0))
  57.     pygame.display.flip()
  58.  
  59.  
  60. if __name__ == '__main__' : main()
RAW Paste Data