# Unicorn Hat - First Days Tinkers

#1

Hello,

Im new to the RPi, Python and Unicorn hat, some I was pretty pleased when I got it up and running quickly. I tinkered around a bit and tried a few of the samples. I saw the rainbow didn’t show all the colours, so I thought I would knock up my code to see if I could make something that would and here’s what I came up with…

``````import unicornhat as u
import time
import math as math

u.brightness(0.2)

r=[0,0,0,0,0,0,0,0]
g=[0,0,0,0,0,0,0,0]
b=[0,0,0,0,0,0,0,0]

def shift(l,n):
return l[n:]+l[:n]

freq = 0.1
while True:
for i in range(64):
r = shift(r,1)
b = shift(b,1)
g = shift(g,1)

r[7] = int(math.sin(freq*i+0)*127+128);
g[7] = int(math.sin(freq*i+2)*127+128);
b[7] = int(math.sin(freq*i+4)*127+128);

for x in range(8):
for y in range(8):
u.set_pixel(x, y, r[x], g[x], b[x])
u.show()``````

setting freq to 0.05 and i to range 128, and putting a time.sleep(0.1) after the u.show() will give a much more subtle fade between the colours.

Cheers,

Andrew

#2

More tinkering on Day 2 :)

Now have a nice RSS feed scroller working…

next step to see if I can get a twitter feed scroller.

#3

Superb stuff. I’ve just got my Pi and Unicorn HAT and some sort of Twitter/HAT integration is going to be my first little project!

#4

How did you get on with the Twitter Feed scroller? Love to see code examples of this and the rss feed one - i learn by othercode (noob)!!!

#5

Thanks for the video. I’m still struggling a bit with understanding the code, but it’s pushing me to read up and learn about Python arrays and matrices. :-)

Ah, as I write this I think I can see what it is doing. I couldn’t understand why you only had one dimensional arrays for the r,g,b variables. I assumed this was to be used in relation to the x,y location. But now I think I see that they are there to produce a stepped colour change and I assume the use of sin gives a curved colour gradient rather than a linear one, and the difference in the formula allows for a cycling through the colour space?

I did a bit of maths at Uni (but obviously not enough!)

Craig

#6

Hi Andrew,

Did you post any code to drive the scrolling display anywhere ?

I just got a Pi 2 setup with the Unicorn Hat and would love to tinker with scrolling text.

Cheers - Paul