Welcome¶
This documentation will guide you through the methods available in the Unicorn HAT python library.
Unicorn HAT is a Raspberry Pi add-on with 64 individually controllable RGB LEDs.
More information - https://shop.pimoroni.com/products/unicorn-hat
GPIO pinout - https://pinout.xyz/unicorn_hat
Get the code - https://github.com/pimoroni/unicorn-hat
Get started - https://learn.pimoroni.com/tutorial/unicorn-hat/getting-started-with-unicorn-hat
Get help - http://forums.pimoroni.com/c/support
At A Glance¶
- unicornhat.COLORS = {'black': (0, 0, 0), 'blue': (0, 0, 255), 'cyan': (0, 255, 255), 'gold': (255, 215, 0), 'gray': (127, 127, 127), 'green': (0, 128, 0), 'grey': (127, 127, 127), 'indigo': (75, 0, 130), 'lime': (0, 255, 0), 'magenta': (255, 0, 255), 'maroon': (128, 0, 0), 'navy': (0, 0, 128), 'olive': (128, 128, 0), 'orange': (255, 165, 0), 'purple': (128, 0, 128), 'red': (255, 0, 0), 'silver': (192, 192, 192), 'teal': (0, 128, 128), 'white': (255, 255, 255), 'yellow': (255, 255, 0)}¶
Store the rotation of UnicornHat, defaults to 0 which places 0,0 on the top left with the B+ HDMI port facing downwards
- unicornhat.ws2812 = None¶
Store a map of pixel indexes for translating x, y coordinates.
Brightness¶
Clear¶
Get Brightness¶
Get Pixel¶
Get Pixels¶
Get Shape¶
Turn Off¶
Rotation¶
Set All¶
Set Layout¶
- unicornhat.set_layout(pixel_map=None)[source]¶
Set the layout to Unicorn HAT or Unicorn pHAT
Note: auto detection relies upon the HAT EEPROM. Your Unicorn HAT must be connected before boot to successfully auto detect.
- Parameters
pixel_map – Choose the layout to set, can be either HAT, PHAT, PHAT_VERTICAL or AUTO
Set Pixel¶
Set Pixel HSV¶
- unicornhat.set_pixel_hsv(x, y, h, s=None, v=None)[source]¶
Set a single pixel to a colour using HSV
- Parameters
x – Horizontal position from 0 to 7
y – Veritcal position from 0 to 7
h – Hue from 0.0 to 1.0 ( IE: degrees around hue wheel/360.0 )
s – Saturation from 0.0 to 1.0
v – Value (also known as brightness) from 0.0 to 1.0
Set Pixels¶
Shade Pixels¶
- unicornhat.shade_pixels(shader, *args)[source]¶
Set all pixels using a pixel shader style function
- Parameters
shader – A function which accepts the x and y positions of a pixel and returns a tuple (r, g, b)
For example, this would be synonymous to clear:
set_pixels(lambda x, y: return 0,0,0)
Or perhaps we want to map red along the horizontal axis, and blue along the vertical:
set_pixels(lambda x, y: return (x/7.0) * 255, 0, (y/7.0) * 255)