CSE Day 1 - Pies and Pythons

Wednesday, Sept. 18th

Turning on a few pixels with code:

1  import unicornhathd as u
2 
3  u.set_pixel(3, 5, 200, 45, 150)
4  u.show()

Let's break it down:

Line 1: The LCD panel on top of the Raspberry Pi is called the UnicornHAT_HD. It has 256 multicolour LEDs in a 16x16 grid. In order to control them, we need to import the code library to control the panel. Rather than type unicornhathd over and over, we can give it an alias with the as command. We will call it u for a nice short name.

Line 3: To tell a LED to turn on or off, we use the set_pixel command. This doesn't actually send electricity to the LED, it just sets it up in the background. The command takes 5 options:  (x location, y location, red, green, blue)

Line 4: To update the actual LED panel, we send the show command. This command has no options so we use empty parenthesis:  show()