Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sense HAT workshop

Ben Nuttall
October 15, 2016

Sense HAT workshop

Sense HAT workshop given at Pi Towers Raspberry Jam, October 2016

Ben Nuttall

October 15, 2016
Tweet

More Decks by Ben Nuttall

Other Decks in Technology

Transcript

  1. Sense HAT workshop • Special made for Tim Peake's Astro

    Pi mission • Sensors, LED display & joystick • Great for science, games and creativity • Works on any Pi model • Emulators also available
  2. Type directly into the Python shell >>> from sense_hat import

    SenseHat >>> sense = SenseHat() >>> sense.show_message(“Hello world”) >>> sense.temperature >>> sense.humidity >>> sense.accelerometer >>> sense.gyroscope >>> sense.orientation
  3. Open a new window and type... from sense_hat import SenseHat

    sense = SenseHat() x = 4 y = 5 r = 19 g = 180 b = 230 sense.set_pixel(x, y, r, g, b) Save and run: Ctrl + S F5
  4. Run! Change the numbers! Run again! from sense_hat import SenseHat

    sense = SenseHat() x = 2 y = 3 r = 222 g = 33 b = 111 sense.set_pixel(x, y, r, g, b) Save and run: Ctrl + S F5
  5. Let the computer pick random numbers... from sense_hat import SenseHat

    from random import randint sense = SenseHat() x = randint(0, 7) y = randint(0, 7) r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) sense.set_pixel(x, y, r, g, b) Save and run: Ctrl + S F5
  6. Random sparkles! from sense_hat import SenseHat from random import randint

    from time import sleep sense = SenseHat() while True: x = randint(0, 7) y = randint(0, 7) r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) sense.set_pixel(x, y, r, g, b) sleep(0.01) Save and run: Ctrl + S F5
  7. Pixel pet from sense_hat import SenseHat from time import sleep

    sense = SenseHat() p = (204, 0, 204) # Pink g = (0, 102, 102) # Dark Green w = (200, 200, 200) # White y = (204, 204, 0) # Yellow e = (0, 0, 0) # Empty
  8. Pixel pet! pet1 = [ e, e, e, e, e,

    e, e, e, p, e, e, e, e, e, e, e, e, p, e, e, p, e, p, e, e, p, g, g, p, y, y, e, e, g, g, g, y, w, y, g, e, g, g, g, g, y, y, e, e, g, e, g, e, g, e, e, e, e, e, e, e, e, e, e ]
  9. Pixel pet! pet2 = [ e, e, e, e, e,

    e, e, e, p, e, e, e, e, e, e, e, e, p, e, e, p, e, p, e, e, p, g, g, p, w, w, e, e, g, g, g, w, y, w, y, e, g, g, g, g, w, w, e, e, e, g, e, g, e, e, e, e, e, e, e, e, e, e, e ]
  10. ...and breathe... while True: print(sense.humidity) if sense.humidity < 60: sense.set_pixels(pet1)

    sleep(0.5) else: sense.set_pixels(pet2) sleep(2) Save and run: Ctrl + S F5
  11. What else can you do? • You've learned how to:

    – Read sensor values – Write text to the screen – Write pixels and pixel art to the screen – Use the sensors to display different pictures when shaken • What else can you do?