from sense_emu import SenseHat ##from sense_hat import SenseHat sense = SenseHat() r = (255, 0, 0) g = (0, 255, 0) b = (0, 0, 255) y = (255, 255, 0) message = "Hi!" ##sense.set_rotation(180) sense.show_letter("Z") ##sense.show_message(message, text_colour=blue) ##sense.clear() sense.set_pixel(0, 0, r) pixels = [ g, g, g, g, g, g, g, g, g, g, g, g, g, g, g, g, g, b, b, g, g, b, b, g, g, b, b, g, g, b, b, g, g, g, g, b, b, g, g, g, g, g, b, b, b, b, g, g, g, g, b, b, b, b, g, g, g, g, b, g, g, b, g, g ] sense.set_pixels(pixels)
from random import randint from time import sleep from sense_emu import SenseHat sense = SenseHat() blue = (0, 0, 255) green = (0, 255, 0) yellow = (255, 255, 0) white = (255, 255, 255) red = (255, 0, 0) black = (0, 0, 0) while True: for event in sense.stick.get_events(): print(event.direction, event.action) if event.action == "pressed": if event.direction == "up": sense.show_letter("U") elif event.direction == "down": sense.show_letter("D") elif event.direction == "left": sense.show_letter("L") elif event.direction == "right": sense.show_letter("R") elif event.direction == "middle": sense.show_letter("M") sleep(0.5) sense.clear()
if z < -0.9: z = -1 if x > 0.9: x = 1 if y > 0.9: y = 1 if z > 0.9: z = 1 print(str(x)+" "+str(y)+" "+str(z)) printMode() # Tryb do przełączania trybów if(mode == switchMode): img = Image(black) hat.set_pixels(img.getData()) hat.show_letter(modeLetters[newMode],back_colour=red) applyRotate(rot=rotate) # Temperatura - wyświetla 2 cyfry na czerwono lub niebiesko # zależnie od tego czy temperatura jest ujemna lub dodatnia. # Jeśli wartość absolutna temperatury jest przynajmniej równa 100 # to zamiast jednej liczby jest wyświetlany znak większości elif(mode == temperatureMode): digit_a_color = black digit_b_color = black t = int(hat.get_temperature()) if t < 0: digit_a_color = blue digit_b_color = blue_dark else: digit_a_color = red digit_b_color = red_dark
from sense_emu import SenseHat import time sense = SenseHat() sense.clear() while 1: for i in range(0, 10): c = str(i) sense.show_letter(c) time.sleep(1) continue
sense = SenseHat() # set colours to use on print out on SenseHat green = (0, 255, 0) red = (255, 0, 0) blue = (0, 0, 255) # clear screen and rotate sense.clear() sense.show_message("Ready to go") # start loop to continuously check for button presses while True: for event in sense.stick.get_events(): # Check if the joystick was pressed if event.action == "pressed": # Check which direction if event.direction == "up": sense.show_letter("T", green) # Letter T for top of stairs sleep(0.5) if event.direction == "down": sense.show_letter("B", red) # Letter B for bottom of stairs sleep(0.5) if event.direction == "middle": # Middle M for joystick press sense.show_letter("M", blue) # Letter B for bottom of stairs sleep(0.5) # Wait a while and then clear the screen sense.clear()
from sense_emu import SenseHat import time s = SenseHat() s.low_light = True s.show_letter("C") count = 1 while True: events = s.stick.get_events() for event in events: if event.action == "pressed": count = count + 1 if count % 2 == 0: s.show_letter("C") else: s.show_letter("A") s.stick.direction_any = do_thing
from sense_emu import SenseHat, ACTION_RELEASED, ACTION_PRESSED, ACTION_HELD sense = SenseHat() pressed = ACTION_PRESSED released = ACTION_RELEASED count = 0 selection = False while True: events = sense.stick.get_events() if events: for e in events: if e.action != released: try: if e.direction == 'up': count += 1 sense.show_letter(str(count)) elif e.direction == 'down': count -= 1 sense.show_letter(str(count)) except: print("Entries only allowed up to 9")
from time import sleep from sense_emu import SenseHat sense = SenseHat() sense.clear() while True: acceleration = sense.get_accelerometer_raw() x = acceleration['x'] y = acceleration['y'] z = acceleration['z'] if abs(x) > 1 or abs(y) > 1 or abs(z) > 1: sense.show_letter("!", (255, 0, 0)) else: sense.show_letter("M", (255, 255, 255)) print("x: {:.1f} y: {:.1f} z: {:.1f}".format(x, y, z)) x = round(acceleration['x'], 0) y = round(acceleration['y'], 0) z = round(acceleration['z'], 0) if x == -1: sense.set_rotation(180) elif y == 1: sense.set_rotation(90) elif y == -1: sense.set_rotation(270) else: sense.set_rotation(0)
from sense_emu import SenseHat from time import sleep sense = SenseHat() e = (0, 0, 0) w = (255, 255, 255) sense.clear() while True: for event in sense.stick.get_events(): # Check if the joystick was pressed if event.action == "pressed": # Check which direction if event.direction == "up": sense.show_letter("U") # Up arrow elif event.direction == "down": sense.show_letter("D") # Down arrow elif event.direction == "left": sense.show_letter("L") # Left arrow elif event.direction == "right": sense.show_letter("R") # Right arrow elif event.direction == "middle": sense.show_letter("M") # Enter key # Wait a while and then clear the screen sleep(0.5) sense.clear()
from sense_emu import SenseHat, ACTION_RELEASED, ACTION_PRESSED, ACTION_HELD sense = SenseHat() pressed = ACTION_PRESSED released = ACTION_RELEASED selection = False while True: events = sense.stick.get_events() if events: for e in events: if e.action == pressed: if selection == False: selection = True sense.show_letter("O") else: selection = False sense.show_letter("S")
from sense_emu import SenseHat import time s = SenseHat() s.low_light = True s.show_letter("K") count = 1 while True: events = s.stick.get_events() for event in events: if event.action == "pressed": count++ if count%2 == 0: s.show_letter("K") else: s.show_letter("B") s.stick.direction_any = do_thing
from sense_emu import SenseHat from time import sleep sense = SenseHat() red = (255, 0, 0) blue = (0, 0, 255) green = (0, 255, 0) white = (255, 255, 255) yellow = (255, 255, 0) sense.show_letter("H", red) sleep(1) sense.show_letter("e", blue) sleep(1) sense.show_letter("l", green) sleep(1) sense.show_letter("l", white) sleep(1) sense.show_letter("o", yellow)
from sense_emu import SenseHat #from sense_hat import SenseHat sense = SenseHat() while True: heading = sense.get_compass() print(heading) if heading < 45 or heading > 315: sense.show_letter("N") elif heading < 135: sense.show_letter("E") elif heading < 225: sense.show_letter("S") else: sense.show_letter("W")
from sense_emu import SenseHat from time import sleep sense = SenseHat() yellow = (255, 255, 0) blue = (0, 0, 255) while True: sense.show_message("Hi, Dan!", text_colour=yellow, back_colour=blue, scroll_speed=(.05)) sense.show_letter("D", text_colour=yellow, back_colour=blue) sleep(1) sense.show_letter("A", text_colour=yellow, back_colour=blue) sleep(1) sense.show_letter("N", text_colour=yellow, back_colour=blue) sleep(1)
from sense_emu import SenseHat # sense_hat for real hardware, sense_emu for emulator from time import sleep sense = SenseHat() # set colours to use on print out on SenseHat green = (0, 255, 0) red = (255, 0, 0) blue = (0, 0, 255) # clear screen and rotate sense.clear() sense.show_message("Ready to go") counting = 1 # start loop to continuously check for button presses while True: sense.show_letter(str(counting), blue) sleep(1) counting = counting + 1
#!/usr/bin/env python from random import randint from time import sleep from sense_emu import SenseHat sense = SenseHat() blue = (0, 0, 255) green = (0, 255, 0) yellow = (255, 255, 0) white = (255, 255, 255) red = (255, 0, 0) black = (0, 0, 0) name = "Mika" def random_colour(): return (randint(0, 255), randint(0, 255), randint(0, 255)) for i in range(len(name)): sense.show_letter(name[i], text_colour=random_colour()) sleep(1) sense.clear()
g = (0, 255, 0) b = (0, 0, 255) y = (255, 255, 0) """define a function for random color""" def random_colour(): rand_r = randint(0, 255) rand_g = randint(0, 255) rand_b = randint(0, 255) rand_y = randint(0, 255) return (rand_r, rand_g, rand_b) """Display text one letter at a time, random colour""" sense.show_letter("I", random_colour(), back_colour=r) sleep(0.8) sense.show_letter("L", random_colour(), back_colour=g) sleep(0.5) sense.show_letter("O", random_colour(), back_colour=b) sleep(0.5) sense.show_letter("V", random_colour(), back_colour=y) sleep(0.5) sense.show_letter("E", random_colour(), back_colour=r) sleep(0.5) """Replace with your child's name""" sense.show_letter("M", random_colour(), back_colour=r) sleep(0.5) sense.show_letter("Y", random_colour(), back_colour=g) sleep(0.8) sense.show_letter("K", random_colour(), back_colour=b)
h = round(h, 1) message = " Humidity: " + str(h) bg = blue sense.show_message(message, scroll_speed=0.05, back_colour=bg) elif event.direction == "left": # taken from: https://projects.raspberrypi.org/en/projects/compass-maze heading = sense.get_compass() if heading < 45 or heading > 315: dir = 'north' elif heading < 135: dir = 'east' elif heading < 225: dir = 'south' else: dir = 'west' bg = green sense.show_letter(dir[0].upper(), text_colour=bg) elif event.direction == "right": # taken from: http://warksjammy.blogspot.com/2017/08/sense-hat-pixel-art-v1.html sense.set_pixels(raspi_logo()) #images[count % len(images)]()) sleep(0.75) sense.set_pixels(raspi_logo_random()) sleep(0.75) #count += 1 elif event.direction == "middle": sense.show_letter("M") # Enter key # Wait a while and then clear the screen sleep(0.5) sense.clear()