Advertisement
Joistaus

Monitor Tiempo Real

Apr 5th, 2020
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. import random
  2. import pygame
  3. import sys
  4. from pygame.locals import *
  5.  
  6. WIDTH = 400
  7. HEIGHT = 100 #se recomienda que la altura sea el valor máximo de las lecturas de arduino
  8. FPS = 30
  9.  
  10. #Colors
  11. BLACK = (0, 0, 0)
  12. GREEN = (0, 255, 0)
  13.  
  14. #Initialize pygame and create window
  15. pygame.init()
  16. pygame.mixer.init()
  17. screen = pygame.display.set_mode((WIDTH,HEIGHT))
  18. pygame.display.set_caption('Monitor')
  19. clock = pygame.time.Clock()
  20.  
  21. #T debe ser un numero entero mayor o igual a 1, preferiblemente que sea divisor de WIDTH
  22. T = 4
  23. #mientras T sea mas grande, mayor será la separación horizontal de la gráfica
  24.  
  25. data = [HEIGHT]
  26. #Game loop
  27. running = True
  28. while running:
  29.     #keep loop running at the right speed
  30.     clock.tick(FPS)
  31.     #Events
  32.     for event in pygame.event.get():
  33.         #check for closing window
  34.         if event.type == QUIT:
  35.             running = False
  36.     #Datos generados aleatoriamente con randint, aqui deberian ir tus lecturas de arduino
  37.     read = random.randint(1, 100)
  38.     #Update
  39.     data = (data + [HEIGHT - read])[-WIDTH//T: ]
  40.     #Draw
  41.     screen.fill(BLACK)
  42.     x = 0
  43.     for i in range(len(data) - 1):
  44.         pygame.draw.line(screen, GREEN, (x, data[i]), (x+T, data[i + 1]))
  45.         x += T
  46.     #Flip after drawing
  47.     pygame.display.flip()
  48.  
  49. pygame.quit()
  50. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement