forked from tdamdouni/Raspberry-Pi-DIY-Projects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsensehat-joystick.py
43 lines (34 loc) · 1.06 KB
/
sensehat-joystick.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
# https://stackoverflow.com/questions/35422667/raspberry-pi-sense-hat-joystick-triggering-event-on-reset
from sense_hat import AstroPi
import time
import datetime
import pygame
from pygame.locals import *
ap = AstroPi()
ap.clear()
pygame.init()
pygame.display.set_mode((640,480))
pressure = 'P: ' + str(int(ap.get_pressure()))
temp = 'T: ' + str(int(ap.get_temperature_from_pressure()))
humidity = 'H: ' + str(int(ap.get_humidity()))
blah = 'blah!'
def handle_event(event):
if event.key == pygame.K_DOWN:
ap.show_message(pressure)
elif event.key == pygame.K_UP:
ap.show_message(temp)
elif event.key == pygame.K_LEFT:
ap.show_message(humidity)
elif event.key == pygame.K_RIGHT:
ap.show_message(blah)
running = True
while running:
for event in pygame.event.get():
if event.type == KEYDOWN:
handle_event(event)
if event.type == KEYUP:
handle_event(event)
if event.type == K_ESCAPE:
running = False
if event.type == pygame.QUIT:
running = False