Adding interactivity to the projects
We can use the built-in push buttons A and B of the Micro:bit to control the speed of the rainbow. We have to use the if
statement in the while
loop. We need to have an extra variable for the speed as follows:
num_pixels = 12 ring = NeoPixel(pin0, num_pixels) maxdelay = 400 mindelay = 10 delay = int(maxdelay+mindelay)/2
And we have to make the following modification to the loop:
try: while True: rainbow(ring, num_pixels, offset = n) ring.show() n = n + 1 if (button_a.is_pressed() and (delay < maxdelay)): delay = delay + 10 elif (button_b.is_pressed() and (delay > mindelay)): &...