TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Ras Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • LED Dance Suit
    • Ferminal
    • Crypto Tracker
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me
  • Random Hacks
    • Movile

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

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

Picture
Layout numbers of the Unicorn
Picture
Powered by Create your own unique website with customizable templates.