Sense HAT workshop

A1995c9abe48450ce2f82d93ca0b863f?s=47 Ben Nuttall
October 15, 2016

Sense HAT workshop

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

A1995c9abe48450ce2f82d93ca0b863f?s=128

Ben Nuttall

October 15, 2016
Tweet

Transcript

  1. 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. 4.

    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. 5.

    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. 6.

    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. 7.

    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. 8.

    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. 9.

    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. 10.

    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. 11.

    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. 12.

    ...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. 14.

    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?