Skip to content

Instantly share code, notes, and snippets.

@joetsoi
Last active December 23, 2016 10:41
Show Gist options
  • Save joetsoi/8eba3acbef2a99654118806159648f53 to your computer and use it in GitHub Desktop.
Save joetsoi/8eba3acbef2a99654118806159648f53 to your computer and use it in GitHub Desktop.
neopixel
from random import randint
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin0, 512)
# Merry Christmas
xmas = [
[
'00000000',
'00000000',
'11111111',
'00000100',
'00011000',
'00000100',
'11111111',
'00000000',
'01111000',
'10100100',
'10100100',
'10100100',
'00111000',
'00000000',
'11111100',
'00001000',
'00000100',
'00000100',
'00001000',
'00000000',
'11111100',
'00001000',
'00000100',
'00000100',
'00001000',
'00000000',
'00011110',
'10100000',
'10100000',
'10100000',
'01111110',
'00000000',
'00000000',
'00000000',
'01111110',
'10000001',
'10000001',
'10000001',
'01000010',
'00000000',
'11111111',
'00000100',
'00000100',
'00000100',
'11111000',
'00000000',
'11111100',
'00001000',
'00000100',
'00000100',
'00001000',
'00000000',
'10000100',
'11111101',
'10000000',
'00000000',
'10001000',
'10010100',
'10010100',
'10010100',
'01100100',
'00000000',
'00000100',
'01111111',
'10000100',
'10000100',
'01000000',
'00000000',
'11111100',
'00000100',
'00000100',
'11111000',
'00000100',
'00000100',
'11111000',
'00000000',
'01100000',
'10010100',
'10010100',
'10010100',
'11111000',
'00000000',
'10001000',
'10010100',
'10010100',
'10010100',
'01100100',
'00000000',
'00000000',
'00000000',
'01110000',
'10001000',
'10001000',
'10001000',
'01010000',
'00000000',
'01110000',
'10001000',
'10001000',
'10001000',
'01110000',
'00000000',
'11111000',
'00010000',
'00001000',
'00001000',
'11110000',
'00000000',
'00001000',
'01111110',
'10001000',
'10001000',
'10001000',
'00000000',
'01110000',
'10101000',
'10101000',
'10101000',
'10110000',
'00000000',
'10001000',
'01010000',
'00100000',
'01010000',
'10001000',
'00000000',
'00001000',
'01111110',
'10001000',
'10001000',
'10001000',
'00000000',
'00000000',
'00000000',
'01110110',
'10010001',
'10010001',
'11010101',
'10111001',
'10010001',
'10000001',
'01111110',
'00000000',
'00000000',
],
[
'11111111',
'00001000',
'00001000',
'00001000',
'11111111',
'00000000',
'01111000',
'10000100',
'10000100',
'10000100',
'01111000',
'00000000',
'10111111',
'00000000',
'00000000',
'00000000',
'11111111',
'00001000',
'00001000',
'00001000',
'11111111',
'00000000',
'01111000',
'10000100',
'10000100',
'10000100',
'01111000',
'00000000',
'10111111',
'00000000',
'00000000',
'00000000',
'11111111',
'00001000',
'00001000',
'00001000',
'11111111',
'00000000',
'01111000',
'10000100',
'10000100',
'10000100',
'01111000',
'00000000',
'10111111',
'00000000',
'00000000',
'00000000',
'01000110',
'10001001',
'10001001',
'10001001',
'01110010',
'00000000',
'01100000',
'10010100',
'10010100',
'10010100',
'11111000',
'00000000',
'11111100',
'00000100',
'00000100',
'00000100',
'11111000',
'00000000',
'00000100',
'01111111',
'10000100',
'10000100',
'01000000',
'00000000',
'01100000',
'10010100',
'10010100',
'10010100',
'11111000',
'00000000',
'10001000',
'10010100',
'10010100',
'10010100',
'01100100',
'00000000',
'00000000',
'00000000',
'00111110',
'10100001',
'10100001',
'10100001',
'01111111',
'00000000',
'00000000',
'01111000',
'10000100',
'10000100',
'10000100',
'01111000',
'00000000',
'00000100',
'01111111',
'10000100',
'10000100',
'01000000',
'00000000',
'00000100',
'01111111',
'10000100',
'10000100',
'01000000',
'00000000',
'01100000',
'10010100',
'10010100',
'10010100',
'11111000',
'00000000',
'00000000',
'00000000',
'00111110',
'10100001',
'10100001',
'10100001',
'01111111',
'00000000',
'00000000',
'01111000',
'10000100',
'10000100',
'10000100',
'01111000',
'00000000',
'10111111',
],
]
intensity = 10
current_col = 0
cur_text = 0
speed = 4
while True:
# intensity = (intensity + 10) % 255
# colours = {
# '0': (0, 0, 0),
# '1': (intensity, 0, 0),
# }
if button_a.is_pressed():
cur_text = 0 # (cur_text + 1) % len(xmas)
elif button_b.is_pressed():
cur_text = 1 # (cur_text - 1) % len(xmas)
if cur_text == 0:
display.show(str(' '))
elif cur_text == 1:
display.show(str('.'))
current_text = xmas[cur_text]
current_col = (current_col + speed) % len(current_text)
green = True
for col, pixel_id in enumerate(range(0, 512, 8)):
this_col = (current_col + col) % len(current_text)
previous_col = (this_col - 1) % len(current_text)
#red = randint(0, 4)
#green = randint(0, 4)
#blue = randint(0, 0)
red = 250
green = 0
blue = 0
if current_text[this_col] == '00000000':
green = not green
#is_green = int((this_col - 3) / 6) % 2
if this_col > 88:
red, green, blue = intensity, 0, 0
elif is_green == 1:
red, green, blue = 0, 10, 0
elif is_green == 0:
red, green, blue = 10, 0, 0
if col % 2 == 1:
for row, pix in enumerate(range(pixel_id, pixel_id + 8)):
msg = current_text[this_col][row]
previous_msg = current_text[previous_col][row]
# colour = colours[msg]
if msg == '1':# and previous_msg == '0':
np[pix] = (red, green, blue)
#elif msg == '0' and previous_msg == '1':
# np[pix] = (0, 0, 0)
else:
np[pix] = (0, 0, 0)
else:
for row, pix in enumerate(range(pixel_id + 7, pixel_id - 1, -1)):
msg = current_text[this_col][row]
previous_msg = current_text[previous_col][row]
if msg == '1':# and previous_msg == '0':
np[pix] = (red, green, blue)
#elif msg == '0' and previous_msg == '1':
# np[pix] = (0, 0, 0)
else:
np[pix] = (0, 0, 0)
np.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment