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



Micro python Robot Course 1: Light up a LED

Posted by SuFiona on

Learning goal:

This lesson we will learn to control a LED light on the Tiny-bit robot.

Preparation:

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

 image.png

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 .

image.png

Code:

from microbit import *

import neopixel

np = neopixel.NeoPixel(pin12, 2)  # RGB light connects to micro:bit's P12 pin

while True:

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

        np[0] = (255, 0, 0)   # red

        np.show()  # Show

        sleep(200)

Programming and downloading

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

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

image.png Figure 1-1

2.As shown in Figure 1-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 1-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 1-3.

image.png Figure 1-3

4.After the download is successful, you can see that a LED light will be lit red, as shown in Figure1-4.

image.png 

Figure 1-4

The code of the experiment: 1.Light up a LED.zip

Micro python Robot Course:

0 comments

Leave a comment

Please note, comments must be approved before they are published