Created
February 14, 2016 21:35
-
-
Save ntoll/47baf69516a1802e2b6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Play a game of squeeky pong with a 1m (30 led) NeoPixel strip. :-) | |
from microbit import * | |
import music | |
import neopixel | |
np = neopixel.NeoPixel(pin1, 30) | |
def show_pixel(position, wait): | |
np[position] = (0, 0, 64) | |
np.show() | |
music.pitch(440 + position * 16, wait) | |
np[position] = (0, 0, 0) | |
def run(): | |
pos = 0 | |
score = 0 | |
pixels = [x for x in range(30)] | |
pause = 100 | |
while True: | |
if button_a.is_pressed(): | |
for pos in pixels: | |
show_pixel(pos, pause) | |
pos += 1 | |
for pos in pixels[::-1]: | |
show_pixel(pos, pause) | |
pos -= 1 | |
score += 1 | |
pause -= 5 | |
display.show("{}".format(score)) | |
else: | |
display.scroll("Score: {}".format(score)) | |
break | |
while True: | |
if button_a.is_pressed(): | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment