RPi::UnicornHatHD - Use Pimoroni's Awesome Unicorn HAT HD in Perl
use RPi::UnicornHatHD;
my $display = RPi::UnicornHatHD->new();
while (1) { # Mini rave!
$display->set_all(sprintf '#%06X', int rand(hex 'FFFFFF'));
for (0 .. 100, reverse 0 .. 100) {
$display->brightness($_ / 100);
$display->show();
}
}
Pimoroni's Unicorn HAT HD crams 256 RGB LEDs, in a 16x16 matrix, onto a single HAT for your Raspberry Pi. Use it for scrolling news or stock quotes. Mount it somewhere as a mood light. Build a binary clock. Uh. I don't know, you'll think of something.
Use these to make pretty pictures.
$display = RPi::UnicornHatHD->new();
Creates a new object representing your Unicorn Hat HD. Obviously.
$display->brightness(.25); # For tinkering at 1a
Set the display brightness between 0.0
and 1.0
. The default is 0.5
.
$display->clear;
Clears the display matrix.
This does not clear the display; it simply resets the 'canvas' for you.
my ($r, $g, $b) = $display->get_pixel(10, 15);
Returns the color this pixel will display.
$display->off;
Clears the display matrix and immediately updates the Unicorn Hat HD.
This turns off all the pixels.
$display->rotation(180);
Set the display rotation in degrees. Actual rotation will be snapped to the nearest 90 degrees.
$display->set_all(0xFF, 0, 0);
$display->set_all('#FF0000');
Turns the entire display a single color.
Either...
$r = Amount of red from 0 to 255
$g = Amount of green from 0 to 255
$b = Amount of blue from 0 to 255
...or...
$h = Hex triplet from #000000 to #FFFFFF
for my $x (1..10) {
$display->set_pixel($x, 10, 1, 1, 1);
}
$display->set_pixel(0, 0, '#FFF000');
Set a single pixel to RGB color.
$x = Horizontal position from 0 to 15
$y = Vertical position from 0 to 15
...and either...
$r = Amount of red from 0 to 255
$g = Amount of green from 0 to 255
$b = Amount of blue from 0 to 255
...or...
$h = Hex triplet from #000000 to #FFFFFF
$display->show;
Outputs the contents of the matrix buffer to your Unicorn HAT HD.
- Buy one: http://shop.pimoroni.com/products/unicorn-hat-hd
- GPIO Pinout: http://pinout.xyz/pinout/unicorn_hat_hd
- Github: https://github.com/sanko/RPi-UnicornHatHD
Copyright (C) Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.
Sanko Robinson [email protected]