What is it?The Unicorn HAT is described as "providing a wash of controllable colour that is ideal for mood-lighting, 8x8 pixel art, persistence of vision effects, status indications, or just blasting colour into your surroundings." Recently mine arrived and it is awesome. It is also a great teaching tool for learning about Pixels, RGB values and Hexadecimal values combining in how a group of LEDs can make a picture, be it a very bright one!
SAFETY WARNING: Ensure the brightness is set to (0.20) otherwise it may damage your eyes. Do not look directly at the LEDs Installing and getting started really is easy, firstly up date your Pi
In the LX Terminal type: sudo apt-get update then sudo apt-get install python-pip python-dev sudo pip install unicornhat |
Unicorn & Minecraft Mash Up |
Next Steps and Colour Codes
Turn the Pi off, sudo halt and then attach the Unicorn HAT, reboot the Pi and get your sunglasses at the ready! The video on the left shows a mash up of Minecraft and the HAT, it changes colour depending on the block ID. Grass is Green and lights up the LEDs green, Sand uses a Yellow and lights the LEDs Yellow, Water is Blue and you guessed it the LEDs are Blue! @ukscone told me that you can use web colour names for the various colours that you want instead of the RGB values. For example you could use the code: webcolors.name _to_rgb('maroon') or webcolors.name _to_rgb('forestgreen'). Here is a link to a table with the names of the various colours
To install and use this feature, in the LX Terminal type: sudo pip install webcolors
To install and use this feature, in the LX Terminal type: sudo pip install webcolors
A Simple Code for LEDs and Colour
There are 64 LEDs arranged on an 8 by 8 grid, each LED can be identified by its X and Y co-ordinate. Remember that the first LED is actually located at 0, 0 not 1,1. See picture one on the right for more examples. The code to get started is very simple and there are a number of sample programs on the Pimorni GitHub repository.
Using Python 2.8, Import the Unicorn HAT Modules: import unicornhat as UH Adjust the brightness with UH.brightness(0.10) Be aware that this is really bright - do not go above (0.20) To turn on an LED use the following code: UH.set_pixel(x, y, 0, 0, 0) where the x and y are the co-ordinates of the LED, for example, the first pixel on the top left would be coded as: UH.set_pixel(0, 0, 0, 0, 0) See the second image below. The last three numbers relate to the RGB colours, 256 is the highest value, so (256, 0, 0) would display a Red LED and (0, 0256 0) would display Green. To show / turn on the LED UH.show() To hide / turn off the LED UH.clear() Final Code: import unicornhat as UH import time UH.brightness(0.10) UH.set_pixel(0, 0, 256, 256, 256) UH.show() time.sleep(1) UH.clear() A great app for creating 8x8 Pixel art for the the Unicorn HAT |