Skip to content

Instantly share code, notes, and snippets.

@ggirou
Last active April 30, 2020 13:08
Show Gist options
  • Save ggirou/043baac39b42b19c55abfd3633f92c70 to your computer and use it in GitHub Desktop.
Save ggirou/043baac39b42b19c55abfd3633f92c70 to your computer and use it in GitHub Desktop.
Rainbow hat XP
import rainbowhat as rh
rh.rainbow.set_pixel(0, 255, 0, 0)
rh.rainbow.show()
#######################
import rainbowhat as rh
import time
while True:
for pixel in range(7):
rh.rainbow.clear()
rh.rainbow.set_pixel(pixel, 255, 0, 0)
rh.rainbow.show()
time.sleep(0.1)
#######################
import rainbowhat as rh
import colorsys
import time
rh.rainbow.clear()
rh.rainbow.show()
while True:
for i in range(101):
h = i / 100.0
r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)]
rh.rainbow.set_all(r, g, b)
rh.rainbow.show()
time.sleep(0.02)
#######################
import rainbowhat as rh
import colorsys
import time
s = 100 / 7
while True:
for i in range(101):
for pixel in range(7):
h = ((i + s * pixel) % 100) / 100.0
# rh.rainbow.clear()
r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 0.1)]
rh.rainbow.set_pixel(pixel, r, g, b)
rh.rainbow.show()
#######################
import rainbowhat as rh
rh.display.print_str('AHOY')
rh.display.show()
#######################
import rainbowhat as rh
i = 0.0
while i < 999.9:
rh.display.clear()
rh.display.print_float(i)
rh.display.show()
i += 0.01
#######################
import rainbowhat as rh
rh.display.clear()
rh.display.set_decimal(0, True)
rh.display.show()
#######################
import rainbowhat as rh
@rh.touch.A.press()
def touch_a(channel):
print('Button A pressed')
rh.lights.rgb(1, 0, 0)
@rh.touch.A.release()
def release_a(channel):
print('Button A released')
rh.lights.rgb(0, 0, 0)
#######################
import rainbowhat as rh
value = 0
def show_value(plus):
global value
value = value + plus
rh.display.clear()
rh.display.print_float(value)
rh.display.show()
@rh.touch.A.press()
def touch_a(channel):
rh.lights.rgb(1, 0, 0)
show_value(-1)
@rh.touch.A.release()
def release_a(channel):
rh.lights.rgb(0, 0, 0)
@rh.touch.B.press()
def touch_b(channel):
rh.lights.rgb(0, 1, 0)
show_value(+1)
@rh.touch.B.release()
def release_b(channel):
rh.lights.rgb(0, 0, 0)
#######################
import rainbowhat as rh
while True:
t = rh.weather.temperature()
p = rh.weather.pressure()
print(t, p)
time.sleep(0.5)
#######################
import rainbowhat as rh
while True:
t = rh.weather.temperature()
rh.display.clear()
rh.display.print_float(t)
rh.display.show()
time.sleep(0.5)
#######################
import rainbowhat as rh
rh.buzzer.note(261, 1)
rh.buzzer.midi_note(60, 1)
song = [68, 68, 68, 69, 70, 70, 69, 70, 71, 72]
for note in song:
rh.buzzer.midi_note(note, 0.5)
time.sleep(1)
#######################
import rainbowhat as rh
while True:
if int(time.time()) % 2 == 0:
rh.display.print_float(float(time.strftime('%H.%M')))
else:
rh.display.print_str(time.strftime('%H%M'))
rh.display.show()
time.sleep(1)
@ggirou
Copy link
Author

ggirou commented Apr 30, 2020

Source: https://github.com/pimoroni/rainbow-hat

In the new terminal window type:

curl https://get.pimoroni.com/rainbowhat | bash

If you choose to download examples you'll find them in /home/pi/Pimoroni/rainbowhat.

Library install for Python 3:

on Raspbian:

sudo apt-get install python3-rainbowhat

other environments:

sudo pip3 install rainbowhat

Library install for Python 2:

on Raspbian:

sudo apt-get install python-rainbowhat

other environments:

sudo pip2 install rainbowhat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment