rero:micro is a child-friendly robot kit using micro:bit that is specially designed to encourage young children to learn coding in a fun and easy manner.
MicroPython is an open source Python programming language interpretor that runs on small embedded development boards.
rero:micro has a ultrasonic sensor connected to micro:bit's P2 to detect or measure the distance of an object.
This is the fourth lesson (DetectObject) for this series. Check out the other lessons in the links below:
- Program micro:bit mobile robot with Python | 1 Colour Splash
- Program micro:bit mobile robot with Python | 2 Play Music
- Program micro:bit mobile robot with Python | 3 Move Around
- Program micro:bit mobile robot with Python | 5 Line Follow
Check out the first lesson (Colour Splash) for the guidelines to setup the software.
DETECT OBJECTCODING
To program the rero:micro you need to add these code:
from reromicro import *
rero = reromicro()
rero.ReadUltrasonic()
returns the distance of the object detected
Here is an example code to detect objects:
from reromicro import *
rero = reromicro()
while True:
if (rero.ReadUltrasonic() < 15):
rero.Brake()
else:
rero.RunMotor(50, 50)
rero:micro brakes when object is detected at 15cm away or nearer, else it keep moving forward in the speed of 50
UPLOAD
Check out the first lesson (Colour Splash) for the guidelines to upload program to rero:micro
LINK FOR THE NEXT LESSON - Program micro:bit mobile robot with Python | 5 Line Follow
Comments
Please log in or sign up to comment.