Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
- import time
- from signal import pause
- x = 3
- y = 3
- sense = SenseHat()
- sense.set_rotation(180)
- while True:
- t = sense.get_temperature()
- p = sense.get_pressure()
- h = sense.get_humidity()
- t = round(t, 1)
- p = round(p, 1)
- h = round(h, 1)
- if t > 18.3 and t < 26.7:
- bg = [0, 100, 0] # green
- else:
- bg = [100, 0, 0] # red
- msgt = "TMP: %sC" % (t)
- msgp = "P: %sbar" % (p)
- msgh = "HUM: %s%%rH" % (h)
- def clamp(value, min_value=0, max_value=7):
- return min(max_value, max(min_value, value))
- def pushed_up(event):
- global y
- if event.action != ACTION_PRESSED:
- sense.show_message(msgt, scroll_speed=0.08, back_colour=bg)
- y = clamp(y + 1)
- def pushed_down(event):
- global y
- if event.action != ACTION_PRESSED:
- sense.show_message(msgp, scroll_speed=0.08, back_colour=bg)
- y = clamp(y - 1)
- def pushed_left(event):
- global x
- if event.action != ACTION_PRESSED:
- sense.show_message(msgh, scroll_speed=0.08, back_colour=bg)
- x = clamp(x + 1)
- def pushed_right(event):
- global x
- x = clamp(x - 1)
- def refresh():
- sense.clear()
- sense.set_pixel(x, y, 255, 255, 255)
- sense.stick.direction_up = pushed_up
- sense.stick.direction_down = pushed_down
- sense.stick.direction_left = pushed_left
- sense.stick.direction_right = pushed_right
- sense.stick.direction_any = refresh
- refresh()
- pause()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement