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

South London Pioneers - Sense HAT

South London Pioneers - Sense HAT

Ben Nuttall

May 21, 2017
Tweet

More Decks by Ben Nuttall

Other Decks in Programming

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. Humidity from sense_hat import SenseHat from time import sleep sense

    = SenseHat() while True: g = int(255 * sense.humidity / 100) sense.clear(0, g, 0) Save and run: Ctrl + S F5 Breathe on the Sense HAT
  8. 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
  9. 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 ]
  10. 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 ]
  11. Joystick def change(ev): if ev.action == 'pressed': sense.set_pixels(pet2) elif ev.action

    == 'released': sense.set_pixels(pet1) sense.stick.direction_middle = change Save and run: Ctrl + S F5
  12. 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 colours • What else can you do?