Skip to content

Instantly share code, notes, and snippets.

@ntoll ntoll/pong.py
Created Dec 27, 2015

Embed
What would you like to do?
NeoPixel Pong using MicroPython for the BBC micro:bit
# Play a game of squeeky pong with a 1m (30 led) NeoPixel strip. :-)
from microbit import *
import music
import neopixel
neopixel.init(pin1, 30)
def show_pixel(position, wait):
neopixel.set_colour(position, 0, 0, 64)
neopixel.show()
music.pitch(440 + position * 16, wait)
neopixel.set_colour(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()
@randmor

This comment has been minimized.

Copy link

commented Mar 30, 2019

When I tried the code above, I got a number of error messages which I suspect is because Nicholas was probably using a beta test version of MicroPython. So, I modified his code to compile without errors, and I modified it to run on the Proto-PIC "Micro:Pixel", a 4x8 Neopixel display add-on board for the BBC Micro:bit. The only change to make it run on the Micro:Pixel board was to change the number of neopixels from 30 to 32. The other change was to make a cut and jump on the Micro:Bit board to use Microbit pin8 instead of pin0 to drive the string of NeoPixels. The Proto-PIC website has a note on how to do this on their page that describes the Micro:Pixel board. Below is the code listing (an image file):
ntollPongV3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.