I’ve also added (and altered) the Blinkt larson.py to my clock.py script so I can use the APA102s as a vitual pendulum (which is why I have #'d the flashing decimal point).
import math
import time
import rainbowhat
rainbowhat.rainbow.set_clear_on_exit()
reds = [0, 0, 0, 0, 0, 3, 1, 10, 1, 3, 0, 0, 0, 0, 0]
start_time = time.time()
while True:
delta = (time.time() - start_time) * 8
# Sine wave, spends a little longer at min/max
# offset = int(round(((math.sin(delta) + 1) / 2) * 7))
# Triangle wave, a snappy ping-pong effect
offset = int(abs((delta % 16) - 8))
for i in range(rainbowhat.rainbow.NUM_PIXELS):
rainbowhat.rainbow.set_pixel(i , reds[offset + i], 1, 1)
rainbowhat.rainbow.show()
str_time = time.strftime("%H%M")
# Display the time
rainbowhat.display.print_number_str(str_time)
# Blink the middle decimal point
# int(time.time() % 2) will alternate 1 0 1 0
# which we can use to directly set the point
#rainbowhat.display.set_decimal(1, int(time.time() % 2))
rainbowhat.display.show()
time.sleep(0.1)
Now for the observant of you if you look at my code and at the video you will notice that the brightest ‘red’ stops at LED number 7 (far right) but doesn’t stop at LED number 1 (far left). It does the same if I change two lines of code to this.
reds = [0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0]
rainbowhat.rainbow.set_pixel(i , reds[offset + i], 0, 0)
Any ideas on how to stop the pendulum at LED 1?