13. Case 05: Crazy Dance#

../../_images/case05.png

13.1. Introduction#

Hello, the Ring:bit car is a powerful kit that can do a lot of things after the 4 former cases, here we will do a relatively simple thing, which is to make a dance car.

13.2. Hardware Connection#

Connect the left wheel servo to P1 of the Ring:bit expansion board and the right wheel servo to P2.

13.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 random import *
from ringbit import *

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

# Set the speed value of the both wheels as the random value among (-100, 100)
while True:
    left_wheel = randint(-100, 100)
    right_wheel = randint(-100, 100)
    ringbit.set_speed(left_wheel, right_wheel)

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 random import *
from ringbit import *

2.Set the pins of the servos

ringbit = Ringbit(board.P2, board.P1)

3.Set the speed value of the both wheels as the random value among (-100, 100)

while True:
    left_wheel = randint(-100, 100)
    right_wheel = randint(-100, 100)
    ringbit.set_speed(left_wheel, right_wheel)

13.4. Result#

The car runs at different speed.

13.5. Exploration#

Design a set of the actions for Ring:bit car with your ideas.

13.6. FAQ#

13.7. Relevant Files#