Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import pygame
- import sys
- from pygame.locals import *
- WIDTH = 400
- HEIGHT = 100 #se recomienda que la altura sea el valor máximo de las lecturas de arduino
- FPS = 30
- #Colors
- BLACK = (0, 0, 0)
- GREEN = (0, 255, 0)
- #Initialize pygame and create window
- pygame.init()
- pygame.mixer.init()
- screen = pygame.display.set_mode((WIDTH,HEIGHT))
- pygame.display.set_caption('Monitor')
- clock = pygame.time.Clock()
- #T debe ser un numero entero mayor o igual a 1, preferiblemente que sea divisor de WIDTH
- T = 4
- #mientras T sea mas grande, mayor será la separación horizontal de la gráfica
- data = [HEIGHT]
- #Game loop
- running = True
- while running:
- #keep loop running at the right speed
- clock.tick(FPS)
- #Events
- for event in pygame.event.get():
- #check for closing window
- if event.type == QUIT:
- running = False
- #Datos generados aleatoriamente con randint, aqui deberian ir tus lecturas de arduino
- read = random.randint(1, 100)
- #Update
- data = (data + [HEIGHT - read])[-WIDTH//T: ]
- #Draw
- screen.fill(BLACK)
- x = 0
- for i in range(len(data) - 1):
- pygame.draw.line(screen, GREEN, (x, data[i]), (x+T, data[i + 1]))
- x += T
- #Flip after drawing
- pygame.display.flip()
- pygame.quit()
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement