...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit...

89

Transcript of ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit...

Page 1: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,
Page 2: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

Count About Micro bit ..................................................................................- 1 -

Lesson 1 Download the Program onto Micro: bit ...................................- 6 -

Lesson 2 Custom Pattern .................................................................. - 10 -

Lesson 3 LED Display Number........................................................... - 11 -

Lesson 4 Make Nameplate ................................................................ - 13 -

Lesson 5 Button Addition Operation................................................... - 15 -

Lesson 6 The Lamp of Shaking.......................................................... - 18 -

Lesson 7 The Arrow to the North ...................................................... - 20 -

Lesson 8 Intelligent Lamp................................................................. - 22 -

Lesson 9 Display the Temperature ..................................................... - 24 -

Lesson 10 The Acceleration Sensor Controls the Servo Angle ............... - 25 -

Lesson 11 The Potentiometer Controls the Angle of the Servo.............. - 28 -

Lesson 12 Read the Value of the Ultrasound ....................................... - 30 -

Lesson 13 Music Player for Micro bit .................................................. - 33 -

Lesson 14 Bluetooth Connection ....................................................... - 35 -

Lesson 15 MU Micro Python Download and Driver Installation .............. - 46 -

Lesson 16 Display the Button Turn State ............................................ - 49 -

Lesson 17 The Flashing LED ............................................................. - 51 -

Lesson 18 Control RGB Color ............................................................ - 54 -

Lesson 19 Active Buzzer ................................................................... - 56 -

Page 3: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

Lesson 20 Passive Buzzer Play the Music ............................................ - 58 -

Lesson 21 Tilt Switch Control LED...................................................... - 61 -

Lesson 22 Photoresistance................................................................ - 64 -

Lesson 23 Read the Value of the Potentiometer .................................. - 66 -

Lesson 24 The Potentiometer Controls the LED................................... - 68 -

Lesson 25 7-segment display 0-9 ...................................................... - 70 -

Lesson 26 Servo Angle ..................................................................... - 73 -

Lesson 27 Rotary encoder ................................................................ - 75 -

Lesson 28 LCD 1602 and IIC Interface Module ................................... - 77 -

Lesson 29 Read PS2 Joystick Value.................................................... - 79 -

Lesson 30 DC Motor Fan................................................................... - 81 -

Lesson 31 Read 4*4 Matrix Keypad Value .......................................... - 83 -

Page 4: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 1 -

About Micro bit

From dancing robots to banana keyboards, your micro: bit has all the features

you need to code awesome stuff - the possibilities are endless!

In 2015, BBC launched the second programmable micro computer, and it is a

super mini computer which can be put in your pocket, meanwhile, it can help

young people learn basic programming knowledge with low cost. In 2016, 100

million micro computers have been provided for middle and primary school

students in Britain.

Page 5: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 2 -

Your micro: bit has the following physical features:

LEDs

Buttons

Pins �

Light Sensor

LED stands for Light Emitting Diode. The micro: bit has 25 individually-programmable LEDs, allowing you to display text, numbers, and images.

There are two buttons on the front of the micro: bit (labelled A and B). You can detect when these buttons are pressed, allowing you to trigger code on the device.

There are 25 external connectors on the edge connector of the micro: bit, which we refer to as 'pins'. Program motors, LEDs, or other electrical components with the pins, or connect extra sensors to control your code! The five big pins connect with the annular hole, and marked as 0, 1, 2, 3V, GND, representing P0, P1, P2, 3V power output

Page 6: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 3 -

Temperature Sensor

Accelerometer

By reversing the LEDs of the screen to become an input, the LED screen works as a basic light sensor, allowing you to detect ambient light.

This sensor allows the micro: bit to detect the current ambient temperature, in degrees Celsius.

An accelerometer measures the acceleration of your micro: bit; this component senses when the micro: bit is moved. It can also detect other actions, e.g. shake, tilt, and free-fall.

Page 7: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 4 -

Compass

Radio

Bluetooth

The compass detects the earth's magnetic field, allowing you to detect which direction the micro: bit is facing. The compass has to be calibrated before it can be used.

'Calibrating' the compass ensures the compass results are accurate. For the JavaScript Blocks Editor, use the 'calibrate compass' block. To calibrate the compass in Python use compass.calibrate().

The radio feature allows you to communicate wirelessly between micro: bits. Use the radio to send messages to other micro: bits, build multiplayer games, and much more!

A BLE (Bluetooth Low Energy) antenna allows the micro: bit to send and receive Bluetooth signals. This allows the micro: bit to wirelessly communicate with PCs, Phones, and Tablets, so you can control your phone from your micro: bit and send code wirelessly to your device from your phone!

Page 8: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 5 -

USB Interface

The USB interface allows you to connect the micro: bit to your computer via a micro-USB cable, which will power the device and allow you to download programs onto the micro: bit.

Page 9: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 6 -

Lesson 1 Download the Program onto Micro: bit

Introduction

In the first lesson, we will learn how to display a heart on micro: bit

The preparation before class:

One piece of BBC micro: bit development board,

A USB cable with data transmission function->start make code programming tool

Operating steps

1.Click the block “On Start” in “Basic”

2.Then we place the block “Show Icon” in the block “On Start”, we can see

that the heart will be inosculated.

Page 10: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 7 -

3. Now we can see that the Simulate Toolbar in the left shows the effect

4.Next click the button below.

5.Now connect the micro: bit development board with the computer->click “My Computer” we can see that a new disk has been added->move the program that has been downloaded successfully to the disk.

Of course you may think this way is a little troublesome, now we will introduce another way that can download code directly onto micro: bit, and if the indicator light keeps blinking, it means the program is being downloaded, otherwise, it means the program has been downloaded successfully.

1. Enter:https://www.touchdevelop.com/microbituploader

Page 11: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 8 -

2. Click the button “ Download ” , when it is finished we only get ZIP compressed files.

3. Next, extract the compressed files to any folder.

4. Then open the first file after uncompress.

Page 12: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 9 -

5. When it shows the icon below, it means waiting for downloading, we can minimize it but can’t quit.

Click the button “Download” directly and we can download the program onto micro: bit.

6.Now we can see a heart on micro: bit development board.

Page 13: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 10 -

Lesson 2 Custom Pattern Introduction

In this lesson, we will learn to display different pictures which we like.

Operating steps

1. Start the micro: bit online programming tool

2. As shown in the figure below, place the block “show leds” in the block “on start”

3. We can use mouse to lighten lattices in the matrix according to what picture

we want.

4.Download the program to the development board. Then we can see a

strawberry shape on micro: bit matrix LED.

Page 14: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 11 -

Lesson 3 LED Display Number Introduction

In this lesson, we will learn how to make matrix LED display number 0-9.

Operating steps

1. First, start the micro: bit online programming tool

2. Click the block “Show Number” in “Basic”

3. Place the blocks “Show Number” successively according to the picture

below.

Click “Download” to transfer the program to the micro: bit, then we can see

the micro: bit displays number 0-9 in cycle.

Page 15: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 12 -

Page 16: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 13 -

Lesson 4 Make Nameplate Introduction

In this lesson, we are going to make nameplates, which means making your

name displayed on micro: bit matrix LED.

Operating steps

1. First, start the micro: bit online programming tool

2. Click the block “Show String” in “Basic”

3. Replace “Hello!” with your name.

Page 17: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 14 -

4. Click “Download” to transfer the code to the micro:bit, then we can see

our names displayed on matrix LED

Page 18: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 15 -

Lesson 5 Button Addition Operation Introduction

In this lesson, we are going to make addition operations with two buttons on

micro: bit

Operating steps

1.First, start the micro: bit online programming tool

2. Then we click the block “On Button A Pressed” in “Input”.

3. When we press the button A, it displays number. (You can choose any

number, and here we choose number 3)

4. Next we drag a button B (the button is optional), and choose number 6 to

display.

Page 19: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 16 -

5.In the end, we need to add the two numbers and display the answer. (A+B

means pressing the two buttons simultaneously)

6.Here we need to calculate the answer and fill in the blank, if we want it to

calculate the answer by itself, we need to learn some algorithmic knowledge in

the future.

7. Now we click “Download” to transfer the code in the micro: bit disk.

Now we can see:

When we press the Button A, it displays number 3.

Page 20: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 17 -

When we press the Button B, it displays number 6.

When we press the button A and B simultaneously, the two numbers will be

added and display number 9.

In this way, we finished a simple addition operation through buttons.

Page 21: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 18 -

Lesson 6 The Lamp of Shaking Introduction

In this lesson, we will learn how to make a shaking heart

Operating steps

1. Start the micro: bit online programming tool

2. Click the block “On Shake” in “Input”

3.Click the block “Show Icon” and choose the pictures you need

Page 22: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 19 -

4. Place the pictures according to the pictures below.

5. Download the program onto the micro bit, when we shake the micro: bit,

the two pictures will switch over mutually, and thus we can see a shaking

heart.

Page 23: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 20 -

Lesson 7 The Arrow to the North Introduction

In this class, we will make a smart development board. No matter how you

rotate, its arrow will always point to the north

Operating steps

1. Start the micro: bit online programming tool

2. Click “Basic”->more; drag the block “show arrow” to the block “on shake”.

3. Change “shake” into the picture below

4. Then add blocks successively, as the following picture shows:

Page 24: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 21 -

5. Download the program onto the micro: bit development board. Finally we

can see that no matter how we shake the development board, its arrow will

always point to the north.

Page 25: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 22 -

Lesson 8 Intelligent Lamp Introduction

In this lesson, we will make an intelligent lamp that when the light is not bright

enough, it will light itself naturally and if the light is bright enough, the

intelligent lamp will turn off.

Operating steps

1.First we need to prepare an extra flashlight and start the micro: bit online

programming tool

2. Start the block “logic->if, then, else “

3. Start the block “0 = 0”

4. Click “Input” -> the block “light level” and change the numbers, as the

following picture shows:

Page 26: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 23 -

5. Then click “basic” –>”show icon”, and click “more”->”clear screen”

6. This code means when the light intensity level is lower than 20, it shows

icon, otherwise, it clears screen.

7. Download the program onto the micro: bit

Experimental phenomena: now we can see the heart on development board is

light, and when we use flashlight to shine on it, the heart extinguishes.

Page 27: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 24 -

Lesson 9 Display the Temperature Introduction

In this lesson, we will make micro: bit display the temperature.

Operating steps

1. Start the micro: bit online programming tool

2.Click “basic”-> the block “show number”

3.Start “Input”->the block “temperature”

4.Download the program onto the micro: bit

5.Now we can see the temperature of the micro: bit.

Page 28: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 25 -

Lesson 10 The Acceleration Sensor Controls the Servo Angle

Introduction

In this lesson, we will learn how to use acceleration sensor to control the

rotation angle of servo.

Operating steps

1.First, we need to prepare a micro: bit expansion board, and start micro:

bit online programming tool.

2. Click “Advance” -> “Pins” -> the block “servo write pin”

3. Click “Input” -> “More”->”rotation”

4. Connect the servo with micro: bit, as the following picture shows

Page 29: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 26 -

5. Download the program onto the micro: bit development board.

6.When we turn the micro: bit with hand, the rotation angle of the servo will

change correspondingly.

Effect picture

Page 30: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 27 -

Page 31: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 28 -

Lesson 11 The Potentiometer Controls the Angle of the Servo

Introduction

In this lesson, we will learn how to control the angle of the servo with the

potentiometer

Operating steps

1. The following are the materials we should prepare before class

1 * micro: bit 1 * micro: bit expansion board 1 * potentiometer 1 * servo - Several Jumper wires

2. First, start the micro Python online programming tool

3. Start “Pins” ->” servo write pin P1”

Then click “map” -> “analog read pin P0”

Finally replace the number 4 in “To High” with 180

Experimental code:

Page 32: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 29 -

4. First, connect the hardware.

Connection diagram:

5. Click “Download” to transfer the code to your micro: bit

6. Now we can rotate the potentiometer with hand, and meanwhile, the servo

will rotate, too.

Effect picture:

Page 33: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 30 -

Lesson 12 Read the Value of the Ultrasound Introduction

In this lesson, we will learn how to read the value of the ultrasound

Operating steps

1. Start Micro:bit online programming tool

2.Add building block-> click “Add Package”- > search “ sonar” ->click

“install”

3. Then the blocks we added will be seen on the column

Page 34: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 31 -

4. Next we begin programming, first click “Variables” -> “set item to”,

building block, and rename “Item” as “Distance”.

5. Then add Sonar –> ping trig,and alter the pin number and unit, as the

following picture shows:

6. Finally we add “Basic” -> “Show number” and “delay function”, and then

set to 100. In this way, we finish the code programming.

As shown below:

Page 35: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 32 -

Now we connect ultrasound with the micro: bit.

Connection diagram:

In the end, we download the code onto the micro: bit. After downloading, we

can see the distance detected by ultrasound on LED matrix lamp.

Effect picture:

Page 36: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 33 -

Lesson 13 Music Player for Micro bit Introduction

In this lesson, we will learn how to change micro: bit into a music player

Operating steps

1. First, we need an earphone cable.

2. Open the micro: bit online programming tool

3. Click “Input” -> the block “on button”

4. Click “Music” -> the block “start melody” and choose the music we want

to listen to and cycle times.

5. Use Alligator to connect the earphone with the micro: bit when the power

is off, and then connect it with the computer

Connection picture:

Page 37: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 34 -

6. Download the program onto the micro: bit.

7. Now, when we press the button A, we can hear the music.

Effect picture:

Page 38: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 35 -

Lesson 14 Bluetooth Connection Introduction

In this lesson, we will learn how to connect mobile phone with micro: bit.

Operating steps

1. preparing the following things

1 * micro bit 1 * USB cable 1 * mobile phone (IOS or Android) (here we choose IOS)

2. Search micro: bit in mobile phone store and download it onto mobile phone

3. When we start the application, we'll see the following interface.

Page 39: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 36 -

4.Connect micro: bit with the computer

5.Turn on the Bluetooth of the mobile phone, and go to the downloaded

micro: bit page, then click “Choose micro: bit”

Page 40: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 37 -

6.Click “pair a micro: bit”

Page 41: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 38 -

7. As the picture shows, we press the buttons A, B at the same time, and press

the button “reset”, and then loosen button “reset”, when the LED matrix lamp

displays “pairing mode”, please loosen button A and B, then go on.

8. Light up the lamps on mobile phone that have been lighten in matrix lamps,

as the picture shows: (notice: each micro: bit shows different when matched),

then click “next”.

Page 42: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 39 -

9. Now we should press the button “A” on micro: bit

Page 43: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 40 -

10. Then we can see that the mobile phone has been connected with the micro:

bit successfully, (notice: before then IOS users run into the situations that

unable to connect or unable to connect again after disconnection, if you meet

this kind of situation, you can change Android to solve this problem.)

Now, we can use mobile phone to control the display of micro” bit lamp

Turn back to the homepage and click “monitor and control”

Enter the page and we can see the following picture, next we click “start”, and

then we can control the micro: bit.

Page 44: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 41 -

Draw a heart on mobile phone’s LED matrix lamp. Now we can see the same

picture on micro: bit as on mobile phone synchronously

Page 45: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 42 -

Android mobile phone connecting steps

1. Prepare an Android mobile phone

2. Enter “Google play” and download, the URL is

https://play.google.com/store/apps/details?id=com.samsung.microbit&r

did=com.samsung.microbit

3. After downloading, start micro: bit APP

4. Start APP you will see the following picture :

5.Connect micro: bit with the computer

6.Turn on the Bluetooth of mobile phone and enter the downloaded micro: bit

page, and click “Choose micro: bit”

7.Click “pair a new micro: bit”

Page 46: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 43 -

8. As the picture shows, we press the buttons A, B at the same time, and press

the button “reset”, and then loosen button “reset”, when the LED matrix lamp

displays “pairing mode”, please loosen button A and B, then go on.

Page 47: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 44 -

9. Light up the lamps on mobile phone that have been lighten in matrix lamps,

as the picture shows: (notice: each micro: bit shows different when matched),

then click “PAIR”.

8. Now we should press micro: bit button A

9. Then we can see that the mobile phone has been connected with the micro:

bit successfully.

Page 48: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 45 -

After learning these two Bluetooth connection modes, we will find that there is

an obvious difference between Android and IOS, that is IOS can control LED to

display the pictures we want, but Android can’t, and the following Bluetooth

experiment waits for you to try

Page 49: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 46 -

Lesson 15 MU Micro Python Download and Driver Installation

Introduction

In this class, we will learn how to install the offline version of MU

Operating steps

Download and install steps:

1.Enter https://codewith.mu/#download

2.Click “ Download” button

3. We can download it according to what operating system we need, here we

choose Windows

Page 50: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 47 -

4.After downloading, open the folder-> start the application program, then we

can see the page below

Page 51: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 48 -

5. Add another REPL plug-in we can display data through gorge line, the

download link is

http://cdn.kittenbot.cn/mbedWinSerial_16466.exe

When finish downloading, we can use it directly

6.In the next lessons, we will use Python language to programming, now we

begin the journey of programming.

Page 52: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 49 -

Lesson 16 Display the Button Turn State Introduction

In this lesson, we will learn how to use micro: bit to read the condition of circumscribed keypads

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * breadboard 1 * button 1 * 10KΩ Resistor - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 53: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 50 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : button.py

# Description: The key state is displayed in led matrix lamp.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

Button State = pin0.read_digital ()

If button State==1:

display.show (Image. YES)

Else:

display. clear()

sleep (20)

5. Click “flash” and download the code onto the micro: bit 6. Now we can see that when the button was pressed, the micro: bit displays “YES”, and when we loosen the button, the micro: bit doesn’t display

Page 54: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 51 -

Lesson 17 The Flashing LED Introduction

In this lesson, we will learn how to make the circumscribed LED flashing

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * LED 1 * 220Ω Resistor - Several Jumper wires

2. Connect micro: bit with the element when the power is off connection diagram:

Page 55: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 52 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : blinking led.py

# Description: led blinking

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

pin0.write_digital(1)

sleep(200)

pin0.write_digital(0)

sleep(480)

5. Click “flash” and download the code onto the micro: bit 6. Now, we can see that the LED is flashing Effect Picture:

Page 56: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 53 -

Page 57: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 54 -

Lesson 18 Control RGB Color Introduction

In this lesson, we will learn how to control RGB color

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * RGB 3 * 220Ω Resistor - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 58: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 55 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : RGB.py

# Description: RGB light switch colors.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

Def set_rgb(red, green, blue):

pin0.write_analog (red)

pin1.write_analog (green)

pin2.write_analog (blue)

While True:

set_rgb(255, 0, 0)

sleep (1000)

set_rgb(800, 100, 0)

sleep(1000)

set_rgb(0, 1023, 0)

sleep(1000)

set_rgb(800, 100, 0)

sleep(1000)

5. Click “flash” and download the code onto the micro: bit Effect Picture:

Page 59: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 56 -

Lesson 19 Active Buzzer Introduction

In this lesson, we will learn how to make active buzzer produce sound.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * Micro: Bit 1 * Micro: Bit Expansion Board 1 * Bread Board 1 * Active buzzer 1 * S8050 1 * 1kΩ resistor - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 60: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 57 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : active_buzzer.py

# Description: Buzzer rang.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

pin0.write_digital (1)

sleep (200)

pin0.write_digital (0)

sleep(200)

5. Click “flash” and download the code onto the micro: bit 6. Now we can hear the active buzzer is ticking. Effect Picture:

Page 61: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 58 -

Lesson 20 Passive Buzzer Play the Music Introduction

In this lesson, we will learn how to make passive buzzer play the music.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * passive buzzer 1 * S8050 1 * 1kΩ resistor - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 62: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 59 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: 5. Click “flash” and download the code onto the micro: bit #-----------------------------------------------------------

# File name : Passive_buzzer.py

# Description: Play system music.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

Import music

music.play(music.BIRTHDAY)

Here we choose the system-provided music; of course we can choose the music we like. Experimental code: #-----------------------------------------------------------

# File name : Passive_buzzer.py

# Description: Play own make music.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

Import music

music.set_tempo(ticks=16,bpm=40)

Tune = ['C6:3','C','C:6','C:3','C','C:6','C:3','D#','G#5','A#',

'C6:12','C#:3','C#','C#:4','C#:2','C#:3','C','C','C2','C',

'C:3','A#5','A#','C6','A#5:6','D#6','C:3','C','C:6','C:3','C',

'C:6','C:3','D#','G#5','A#','C6:12','C#:3','C#','C#:4','C#:2',

'C#:3','C','C','C2','C','D#:3','D#','C#','A#5','G#:8','G#:3',

'G#','F6','D#','C#','G#5:8','G#:3','G#','F6','D#','C#',

'A#5:8','A#3','A#','F#6','F','D#','G#','G#','G#','G#:2','G#',

'A#:3','G#','F#','D#','C#:6']

music.play(tune)

6. Click “flash” and download any code above onto the micro: bit

Page 63: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 60 -

7. Now we can hear the melodious music Effect Picture:

Page 64: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 61 -

Lesson 21 Tilt Switch Control LED Introduction

In this lesson, we will learn how to control a LED lamp with a tilt switch.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * tilt switch 1 * LED 1 * 220Ω Resistor 1 * 10kΩResistor - Several Jumper wires

2. Connect micro: bit with the element when the power is off connection diagram:

Page 65: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 62 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : tilt_switch.py

# Description: tilt switch control led

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

#if pin1.read_digital() == 1

If pin1.read_digital():

pin0.write_digital(1)

Else:

pin0.write_digital(0)

sleep(10)

Page 66: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 63 -

5. Click “flash” and download the code onto the micro: bit Effect Picture:

Page 67: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 64 -

Lesson 22 Photoresistance Introduction

In this lesson, we will learn how to display the voltage values of the photoresistance on LED matrix.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * Photoresistance 1 * 10kΩ Resistor - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 68: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 65 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : photoresistance.py

# Description: Read the resistance of the photosensitance.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

reading = pin0.read_analog()

number = int(reading / 50)

display.show(str(number))

5. Click “flash” and download the code onto the micro: bit Effect Picture:

Page 69: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 66 -

Lesson 23 Read the Value of the Potentiometer

Introduction

In this lesson, we will learn how to read the analog value of the potentiometer into LED matrix lamp

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * potentiometer - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 70: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 67 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : Potentiomenter.py

# Description: Read the value of the potentiometer.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

## pot_reading variable is the reading from pin0

potentiometer_reading = pin0.read_analog()

display.scroll(str(potentiometer_reading))

sleep(1000)

5. Click “flash” and download the code onto the micro: bit 6. Now we can see the value of potentiometer rolling display on micro: bit Effect Picture:

Page 71: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 68 -

Lesson 24 The Potentiometer Controls the LED

Introduction

In this lesson, we will learn how to use the potentiometer control the gradient of the LED

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * potentiometer - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 72: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 69 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : Potentiomenter_control_led.py

# Description: Potentiomenter control led brightness.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

# set_pixel brightness if between 0 - 9

brightness = int((pin0.read_analog() / 1023) * 9)

display.set_pixel(2, 2, brightness)

sleep(10)

5. Click “flash” and download the code to micro: bit 6. Now we can use potentiometer control the brightness of the LED Effect Picture:

Page 73: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 70 -

Lesson 25 7-segment display 0-9 Introduction

In this lesson, we will learn how to make 7-segment display 0-9

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * 7-segment - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

3. Connect micro: bit with the computer

Page 74: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 71 -

4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : 7-segment.py

# Description : 7-segment display 0-9.

# Author : jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

from microbit import *

pins = [pin0, pin1, pin2, pin8, pin12, pin13, pin14, pin15]

# Loop display number

digits = [0b11111101,0b01100001,0b11011011,0b11110011,

0b01100111,0b10110111,

0b10111111,0b11100001,0b11111111,0b11110111]

def WriteDigit(d):

bits = [digits[d] >> i & 1 for i in range(7,-1,-1)]

for p in range(0,8):

pins[p].write_digital(bits[p])

while True:

for i in range(0,10):

WriteDigit(i)

sleep(1000)

5. Click “flash” and download the code onto the micro: bit 6. Now we can see that the 7-segment displays 0-9 in cycle. Effect Picture:

Page 75: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 72 -

Page 76: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 73 -

Lesson 26 Servo Angle Introduction

In this lesson, we will learn how to use micro: bit to rotate the angle of the servo

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * servo - Several Jumper wires

2. Connect micro: bit with the element when the power is off connection diagram:

Page 77: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 74 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : Servo.py

# Description: Angle of rotation of servo.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From microbit import *

pin0.set_analog_period (20)

While True:

pin0.write_analog (180)

sleep(1000)

pin0.write_analog(1)

sleep(1000)

5. Click “flash” and download the code onto the micro: bit 6. Now we can see the servo is rotating from 1 to 180 degrees Effect Picture:

Page 78: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 75 -

Lesson 27 Rotary encoder Introduction

In this lesson, we will learn how to use rotary encoder

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * Rotary encoder - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 79: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 76 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: Refer to lesson 27 Rotary encoder -> code 5. Click “flash” and download the code to micro: bit 6. Now we can see that when we rotate the rotary encoder clockwise, the LED rotates clockwise, otherwise, when we rotate the rotary encoder anticlockwise, the LED rotates anticlockwise. Effect Picture:

Page 80: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 77 -

Lesson 28 LCD 1602 and IIC Interface Module Introduction

In this class, we will learn how to make four digital LED displays from 0-9.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * bread board 1 * LCD 1602 Module1 * IIC Interface Module - Several Jumper wires 2. Connect micro: bit with the element when the power is offconnection diagram:

Page 81: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 78 -

3. Connect micro: bit with the computer4. Start offline MU programming tool and export the codeExperimental code: Refer to lesson 28 LCD 1602 and IIC interface module –>code 5. Click “flash” and download the code onto the micro: bit6. Now we can see clearly that LCD displays “welcome to www.adeept.com”

Effect Picture:

Page 82: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 79 -

Lesson 29 Read PS2 Joystick Value Introduction

In this lesson, we will learn how to read PS2 joystick value.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * ps2 Joystick - Several Jumper wires 2. Connect micro: bit with the element when the power is offconnection diagram:

3. Connect micro: bit with the computer4. Start offline MU programming tool and export the codeExperimental code: #-----------------------------------------------------------

# File name : ps2_rocker.py

# Description: Read the ps2 rocker value in repl.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

Page 83: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 80 -

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

x = pin1.read_analog ()

y = pin2.read_analog ()

z = pin8.read_digital ()

print(x,y,z)

sleep(20)

5. Click “flash” and download the code onto the micro: bit 6. When we start “Repl”, we can see the value of the PS2 joystick Effect Picture:

Page 84: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 81 -

Lesson 30 DC Motor Fan Introduction

In this lesson, we will learn how to make a motor fan.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * motor module 1 * blades - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

Page 85: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 82 -

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : DC_fan.py

# Description: micro control DC motor.

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

#-----------------------------------------------------------

From micro: bit import *

While True:

If button_a.is_pressed():

pin0.write_digital(1)

Else:

pin0.write_digital(0)

sleep(50)

5. Click “flash” and download the code onto the micro:bit 6. Now, when we press the button A, the motor fan begins to rotate. If it can’t start, that’s because it is under voltage, we just need to add another (5V) power source. Effect Picture:

Page 86: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 83 -

Lesson 31 Read 4*4 Matrix Keypad Value Introduction

In this lesson, we will learn how to read the value of 4*4 matrix keypad.

Operating steps

1. First, we need to prepare the following experimental materials:

1 * micro: bit 1 * micro: bit Expansion board 1 * 4*4 matrix keyboard - Several Jumper wires 2. Connect micro: bit with the element when the power is off connection diagram:

3. Connect micro: bit with the computer 4. Start offline MU programming tool and export the code Experimental code: #-----------------------------------------------------------

# File name : keypad.py

# Description: Read the value of the 4*4 matrix keyboard..

# Author : Jason

# E-mail : [email protected]

# Website : www.adeept.com

# Date : 2018/05/02

Page 87: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 84 -

#-----------------------------------------------------------

From micro: bit import *

#define button value

keys=[["1","2","3","A"],

["4","5","6","B"],

["7","8","9","C"],

["*","0","#","D"]]

While True:

row = 0

colume = 0

pin12.read_digital()

pin13.read_digital()

pin14.read_digital()

pin15.read_digital()

pin0.write_digital(1)

pin1.write_digital(1)

pin2.write_digital(1)

pin8.write_digital(1)

#Check row button

row = pin12.read_digital()+

pin13.read_digital()*2+pin14.read_digital()*3+pin15.read_digital()*4

pin0.read_digital()

pin1.read_digital()

pin2.read_digital()

pin8.read_digital()

pin12.write_digital(1)

pin13.write_digital(1)

pin14.write_digital(1)

pin15.write_digital(1)

#Check colume button

colume = pin0.read_digital()+

pin1.read_digital()*2+pin2.read_digital()*3+pin8.read_digital()*4

if (colume+row != 0):

display.scroll(str(keys[colume-1][row-1]))

sleep(100)

5. Click “flash” and download the code onto the micro: bit 6. Now, we just need to press any key, the matrix lamp will display in a rolling way. (Notice: pressing multi-keys at the same time is not supported, otherwise, there will be messy code)

Page 88: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,

www.adeept.com

- 85 -

Effect Picture:

Page 89: ...Micro: bit Introduction . In the first lesson, we will learn how to display a heart on micro: bit . The preparatoi n before cal ss: One piece of BBC micro: bit development board,