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¶
Brightness¶
-
unicornhat.
brightness
(b=0.2)[source] Set the display brightness between 0.0 and 1.0
0.2 is highly recommended, UnicornHat can get painfully bright!
Parameters: b – Brightness from 0.0 to 1.0 (default 0.2)
Get Brightness¶
-
unicornhat.
get_brightness
()[source] Get the display brightness value
Returns a float between 0.0 and 1.0
Get Pixel¶
-
unicornhat.
get_pixel
(x, y)[source] Get the RGB value of a single pixel
Parameters: - x – Horizontal position from 0 to 7
- y – Veritcal position from 0 to 7
Get Pixels¶
-
unicornhat.
get_pixels
()[source] Get the RGB value of all pixels in a 7x7x3 2d array of tuples
Turn Off¶
-
unicornhat.
off
()[source] Clear the buffer and immediately update UnicornHat
Turns off all pixels.
Rotation¶
-
unicornhat.
rotation
(r=0)[source] Set the display rotation
Parameters: r – Specify the rotation in degrees: 0, 90, 180 or 270
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¶
-
unicornhat.
set_pixel
(x, y, r, g, b)[source] Set a single pixel to RGB colour
Parameters: - x – Horizontal position from 0 to 7
- y – Veritcal position from 0 to 7
- r – Amount of red from 0 to 255
- g – Amount of green from 0 to 255
- b – Amount of blue from 0 to 255
Set Pixel HSV¶
-
unicornhat.
set_pixel_hsv
(x, y, h, s, v)[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
Shade Pixels¶
-
unicornhat.
shade_pixels
(shader)[source] Set all pixels using a pixel shader style function
Parameters: pixels – A function which accepts the x and y positions of a pixel and returns values r, g and 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)