Micro python Robot Course 3.Breathing light

Posted by SuFiona on

Learning goal

This lesson we will learn how to control two LED light to become breathing light with the tiny -bit microbit robot.


1.The position of the LED lights in the robot car, as shown below.


2. The micro:bit pins connected to the two LED lights.

From the hardware interface manual, we can know that two LED lights are directly driven by P12 of micro:bit .



from microbit import *

import neopixel


np = neopixel.NeoPixel(pin12, 2)    

# Two RGB light of Tiny-bit connect to Pin 12 of micro:bit


while True:

    for num1 in range(255, 0, -1):    # From 255 to 0, increase by -1 each time

        for pixel_id in range(0, len(np)):

            np[pixel_id] = (num1, 0, num1)    # purple



            # RGB lights are changed gradually from light to dark

    for num1 in range(0, 255, 1):    # From 0 to 255, increase by 1 each time

        for pixel_id in range(0, len(np)):

            np[pixel_id] = (num1, 0, num1)   # purple



            # RGB lights are changed gradually from dark to light


Programming and downloading

1.1.You should open the Mu software, and enter the code in the edit window, , as shown in Figure3-1.

Note! All English and symbols should be entered in English, and the last line must be a space.

image.png Figure 3-1

2.As shown in Figure 3-2, you need to click the Check button to check if our code has an error. If a line appears with a cursor or an underscore, the program indicating this line is wrong.

image.png Figure 3-2

3.You need to connect the micro data cable to micro:bit and the computer, then click the Flash button to download the program to micro:bit as shown in Figure 3-3.

image.png Figure 3-3

4.After the download is successful,we can see the purple LED lights on the Tiny-bit car from on tooff, from off to on, to achieve the effect of breathing lights.

image.png    image.png

The code of the experiment: 3.Breathing

Micro python Robot Course:


Leave a comment

Please note, comments must be approved before they are published