Case06 Reverse Stall Parking
Contents
14. Case06 Reverse Stall Parking#
14.1. Introduction#
Hello, we have programmed the Ring:bit car to do a lot of things, we can also make it automatically drive to the parking lot. In this lesson, we will program to reverse the Ring:bit car into the garage, let’s start.
14.2. Hardware Connection#
Connect the left wheel servo to P1 of the Ring:bit expansion board and the right wheel servo to P2.
14.3. Software Programming#
You should prepare the programming platform ready, if not, please can refer to this essay:Preparation for programming
Sample Projects#
# 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 to change the speed of both wheels by pressing button A/B on pico:ed
while True:
if button_a.is_pressed():
ringbit.set_speed(-100, -60)
sleep(3)
ringbit.set_speed(0, 0)
elif button_b.is_pressed():
ringbit.set_speed(100, 60)
sleep(3)
ringbit.set_speed(0, 0)
Details of program:#
1.Import the modules that we need. board
is the common container, and you can connect the pins you’d like to use through it; ringbit
module contains classes and functions for Ring:bit smart car operation and the random
module contains functions to generate random numbers.
import board
from ringbit import *
from picoed import *
from time import *
2.Set the pins of the servos.
ringbit = Ringbit(board.P2, board.P1)
3.Set to change the speed of both wheels by pressing button A/B on pico:ed.
while True:
if button_a.is_pressed():
ringbit.set_speed(-100, -60)
sleep(3)
ringbit.set_speed(0, 0)
elif button_b.is_pressed():
ringbit.set_speed(100, 60)
sleep(3)
ringbit.set_speed(0, 0)while True:
14.4. Result#
Achieve the functions of reversing stall parking and driving away by pressing buttons A/B on Pico:ed.
14.5. Exploration#
How can make the Ring:bit car move forward and then reverse stall parking?