Unicorn HAT - Python FUNCTION REFERENCE
The unicorn HAT can be programmed using Python. You must tell your python program to import the unicornhat module. You can then use any of the unicorn functions as in the following example code:
import unicornhat as unicorn
unicorn.rotation(0)
unicorn.brightness(0.4)
Unicorn functions available are as follows:
rotation( 90 )
Set the rotation of your Unicorn HAT's output, can be one of 0, 90, 180 or 270 degrees.
brightness( 0.5 )
Set the global brightness of Unicorn HAT. This defaults to 0.2 to save your eyes, but can be anywhere from 0.0 to 1.0.
clear()
Clears the buffer, setting all pixels to RGB 0,0,0. This won't update UnicornHAT until you call show()
off()
Clears the buffer and updates Unicorn HAT immediately by calling clear, and then show for you.
set_pixel(x, y, r, g, b)
Sets the pixel at x,y to colour r,g,b. The x and y values should be between 0 and 7, and r, g, b between 0 and 255. The actual brightness value displayed will depend upon the global brightness.
get_pixel(x, y)
Returns the colour of the pixel at x, y as a tuple of 3 items from 0 to 255.
set_pixels(pixels)
Accepts a 2d list of pixels of dimensions 8:8 ( [[0]8]8 ). Can be used to set the whole buffer in one go from a numpy array.
get_pixels()
Gets the whole pixel buffer as a 2d list of dimensions 8:8.
show()
Updates the Unicorn HAT with the current buffer. The buffer contains all pixel data that you have drawn with the set_pixel or set_pixels methods.
import unicornhat as unicorn
unicorn.rotation(0)
unicorn.brightness(0.4)
Unicorn functions available are as follows:
rotation( 90 )
Set the rotation of your Unicorn HAT's output, can be one of 0, 90, 180 or 270 degrees.
brightness( 0.5 )
Set the global brightness of Unicorn HAT. This defaults to 0.2 to save your eyes, but can be anywhere from 0.0 to 1.0.
clear()
Clears the buffer, setting all pixels to RGB 0,0,0. This won't update UnicornHAT until you call show()
off()
Clears the buffer and updates Unicorn HAT immediately by calling clear, and then show for you.
set_pixel(x, y, r, g, b)
Sets the pixel at x,y to colour r,g,b. The x and y values should be between 0 and 7, and r, g, b between 0 and 255. The actual brightness value displayed will depend upon the global brightness.
get_pixel(x, y)
Returns the colour of the pixel at x, y as a tuple of 3 items from 0 to 255.
set_pixels(pixels)
Accepts a 2d list of pixels of dimensions 8:8 ( [[0]8]8 ). Can be used to set the whole buffer in one go from a numpy array.
get_pixels()
Gets the whole pixel buffer as a 2d list of dimensions 8:8.
show()
Updates the Unicorn HAT with the current buffer. The buffer contains all pixel data that you have drawn with the set_pixel or set_pixels methods.
Blinkt - PYTHON FUNCTION REFERENCE
The Blinkt can be programmed using python. The two Blinkt methods you'll most commonly use are set_pixel and show.
Here's a simple example:
from blinkt import set_pixel
show set_pixel(0,255,0,0)
show()
set_pixel takes an optional fifth parameter; the brightness from 0.0 to 1.0.
set_pixel(pixel_number, red, green, blue, brightness)
You can also change the brightness with set_brightness from 0.0 to 1.0, for example:
from blinkt import set_brightness
set_brightness(0.5)
show()
Here's a simple example:
from blinkt import set_pixel
show set_pixel(0,255,0,0)
show()
set_pixel takes an optional fifth parameter; the brightness from 0.0 to 1.0.
set_pixel(pixel_number, red, green, blue, brightness)
You can also change the brightness with set_brightness from 0.0 to 1.0, for example:
from blinkt import set_brightness
set_brightness(0.5)
show()