The NeoPixel library
The NeoPixel library in the Micro:bit allows us to write programs for NeoPixel products and their compatible devices. You can find out more about the library at https://microbit-micropython.readthedocs.io/en/v1.0.1/neopixel.html. The library comes with MicroPython; we do not have to do anything extra to enable it. Let’s start coding. I am going to connect the NeoPixel 12-LED ring to pin 0 for this chapter. The code examples have been written while considering this circuit. However, I will explain where to make changes if you have opted for a different configuration.
Check the following code example:
from microbit import * from neopixel import NeoPixel num_pixels = 12 ring = NeoPixel(pin0, num_pixels) for i in range(0, 120, 10): print(i) ring[int(i/10)] = [0, 0, i] ring.show()
The first two lines are used to import the required libraries. Then, we assign the number of LEDs in the NeoPixel product to...