Spring Sale: 5% OFF Over \$89, Code: Elephant5; 10% OFF Over \$149, Code:Elephant10

# 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.

Preparation：

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 .

Code

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

np.show()

sleep(5)

# 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

np.show()

sleep(5)

# RGB lights are changed gradually from dark to light

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.

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.

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.

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.

The code of the experiment: 3.Breathing light.zip

Micro python Robot Course：