Case 02: Make A Shape
9. Case 02: Make A Shape#
Hi, after the learn of the first lesson, I am sure you understand the programming for Ring:bit car in a quite simple way, let’s move on by making the car run along with a shape.
9.2. Hardware Connection#
Just as what we do in the first lesson, connect the left wheel servo to P1 of the Ring:bit expansion board and the right wheel servo to P2.
9.3. Software Programming#
You should prepare the programming platform ready, if not, please can refer to this essay: Preparation for programming
# Import the modules that we need import board from ringbit import * from picoed import * from time import * # Set the pins of the servos ringbit = Ringbit(board.P2, board.P1) # While true, set the [Ring:bit](https://www.elecfreaks.com/elecfreaks-micro-bit-ring-bit-v2-car-kit-without-micro-bit-board.html) car run along with a square-like routine while True: ringbit.set_speed(-100, -100) sleep(1.5) ringbit.set_speed(-50, 0) sleep(1.2)
Details of program:#
Import the modules that we need.
boardis the common container, and you can connect the pins you’d like to use through it;
ringbitmodule contains classes and functions for Ring:bit smart car operation;
picoedmodule contains the operation functions to button A/B and
timemodule contains the operation functions to time.
import board from ringbit import * from picoed import * from time import *
Set the pins of the servos.
ringbit = Ringbit(board.P2, board.P1)
Set the Ring:bit car run along with a square-like routine.
while True: ringbit.set_speed(-100, -100) sleep(1.5) ringbit.set_speed(-50, 0) sleep(1.2)
The car runs along with a square-like routine.
If we want the Ring:bit car to travel with a square pentagon routine, how can we program it?