Skip to content

Instantly share code, notes, and snippets.

@ntoll
Created February 14, 2016 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntoll/47baf69516a1802e2b6a to your computer and use it in GitHub Desktop.
Save ntoll/47baf69516a1802e2b6a to your computer and use it in GitHub Desktop.
# 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