Micro:bit Rainbow Lighting (with Expansion Board)
Overview
Warning
- This code only supports Micro:bit v2 or above.
Demo
Code
Library
- Because I use Expansion Board, please add Neopixel extension in your micro:bit editor (https://makecode.microbit.org/pkg/microsoft/pxt-neopixel)
Block code
-
This is the block code, you can click Edit button to check the code.
Python code
-
If you prefer Python, the following is the code. (I use block only to develop this.)
1run = 0 2item: neopixel.Strip = None 3 4def on_button_pressed_a(): 5 global run, item 6 run = 1 7 while run == 1: 8 item = neopixel.create(DigitalPin.P2, 24, NeoPixelMode.RGB) 9 item.show_rainbow(1, 360) 10 for index in range(30): 11 item.show() 12 item.rotate(1) 13 basic.pause(50) 14input.on_button_pressed(Button.A, on_button_pressed_a) 15 16def on_button_pressed_b(): 17 global run 18 item.show_color(neopixel.colors(NeoPixelColors.BLACK)) 19 item.clear() 20 run = 0 21input.on_button_pressed(Button.B, on_button_pressed_b) 22 23def on_forever(): 24 pass 25basic.forever(on_forever)
Q&A
-
If you get error code 207
If you get error code 207 during downloading, it means you are using Micro:bit V1 (You can reference error code from https://makecode.microbit.org/device/error-codes)
Reference
- https://github.com/YahboomTechnology/RGB-LED-Circular-expansion-board
- https://www.circuspi.com/index.php/2019/08/15/mooncarlesson3/ (Chinese)
- https://www.elecfreaks.net/learn-cn/microbitKit/experiment_box/experiment_box_case_10.html (Chinese)