Created
March 6, 2017 22:48
-
-
Save hho/393d4e39610071e9b3e97a22eac6b9b0 to your computer and use it in GitHub Desktop.
RasPi Sense Hat Experiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: latin1 -*- | |
from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED | |
from time import sleep | |
from signal import pause | |
sense = SenseHat() | |
def readout(): | |
t = sense.get_temperature() | |
msg = "{:.1f}C".format(t) | |
sense.show_message(msg, scroll_speed=0.05, text_colour = [200,0,0]) | |
sleep(1) | |
p = sense.get_pressure() | |
msg = "{:.0f}mbar".format(p) | |
sense.show_message(msg, scroll_speed=0.05, text_colour = [0,120,0]) | |
sleep(1) | |
h = sense.get_humidity() | |
msg = "{:.0f}%rH".format(h) | |
sense.show_message(msg, scroll_speed=0.05, text_colour = [0,0,200]) | |
sleep(1) | |
sense.clear() | |
def number(): | |
_ = [0, 0, 0] | |
x = [255, 255, 255] | |
image = [ | |
x, x, x, _, x, x, x, _, | |
_, _, x, _, x, _, x, _, | |
_, x, x, _, x, _, x, _, | |
_, _, x, _, x, _, x, _, | |
x, x, x, _, x, x, x, _, | |
_, _, _, _, _, _, _, _, | |
_, _, _, _, _, _, _, _, | |
_, _, _, _, _, _, _, _, | |
] | |
sense.set_pixels(image) | |
def joystick(): | |
night = False | |
sense.show_letter('0', text_colour = [0,0,0], back_colour = [255,255,255]) | |
while True: | |
event = sense.stick.wait_for_event() | |
#print "Event {0} - {1}".format(event.action, event.direction) | |
if event.action == ACTION_RELEASED: | |
if event.direction == 'middle': | |
night = not night | |
sense.low_light = night | |
if night == True: | |
print "render 1" | |
sense.show_letter('1', text_colour = [0,0,0], back_colour = [255,255,255]) | |
else: | |
print "render 0" | |
sense.show_letter('0', text_colour = [0,0,0], back_colour = [255,255,255]) | |
def main(): | |
try: | |
readout() | |
except KeyboardInterrupt: | |
sense.clear() | |
if __name__ == '__main__': main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment