10. Case 03: Turn at An Angle#

../../_images/case03.png

10.1. Introduction#


Hello, we’ve learnt how to run a shape in case 02, but how can we draw a circle with the Ring:bit car? Let’s start this case with the question.

10.2. Hardware Connection#

Also with the same assembly steps with former practices, connect the left wheel servo to P1 of the Ring:bit board and the right wheel servo to P2.

../../_images/case.png

Use a rubber band to fix a pencil on the base board of the Ring:bit car.

../../_images/case0301.png

10.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 *

# Set the pins of the servos
ringbit = Ringbit(board.P2, board.P1)

# While true, detect if button A/B is pressed to make the [Ring:bit](https://www.elecfreaks.com/elecfreaks-micro-bit-ring-bit-v2-car-kit-without-micro-bit-board.html) car drive the circle or stop. 
while True:
    if button_a.is_pressed():
        ringbit.set_speed(-100, -50)
    elif button_b.is_pressed():
        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; picoed module contains the operation functions to button A/B.

    import board
    from ringbit import *
    from picoed import *
    
  2. Set the pins of the servos.

    ringbit = Ringbit(board.P2, board.P1)
    
  3. While true, detect if button A/B is pressed to make the Ring:bit car drive the circle or stop.

    while True:
        if button_a.is_pressed():
            ringbit.set_speed(-100, -50)
        elif button_b.is_pressed():
            ringbit.set_speed(0, 0)
    

10.4. Result#

On button A pressed, the car draws a circle.

On button B pressed, stop the car.

10.5. Exploration#

How can you make your car draw a figure of eight?

10.6. FAQ#

10.7. Relevant Files#