Tests
Follow these step-by-step instructions to test the tilt-drive and button Gripper control functions.
- Hold the micro:bit tilt controller level with the LED matrix facing the ceiling and the edge connector pointing away from you.
- Disconnect the cyber:bot robot with Gripper from the USB.
- Set the cyber:bot robot with Gripper on the floor and set its PWR switch to 2.
- Tilt the micro:bit away from you and the cyber:bot should roll forward.
- Also try tilting the micro:bit toward you to make the cyber:bot roll backward.
- While rolling either forward or backward, you can also tilt the micro:bit left/right to add turning.
- Hold the micro:bit level again to make the cyber:bot stop.
- Press/release the B button. Verify that the Gripper paddles close and lift.
- Press/release the A button and verify that the Gripper paddles lower and open.
How the Project Scripts Work
The scripts in this project are just slightly expanded versions of the ones from the Cybersecurity: Radio Tilt Control tutorial’s Radio Tilt Controlled cyber:bot activity.
To add button control to the Radio Tilt Controller Code, the routine below was added to the transmitter app. It expands the dictionary to contain data indicating which of the micro:bit module’s buttons were pressed. Before this, it just contained x, y, and needle key value pairs.
if button_b.was_pressed(): # add dictionary['button'] = 'B' # add elif button_a.was_pressed(): # add dictionary['button'] = 'A' # add else: dictionary['button'] = 'None' # add
This line was added to the Radio Controlled cyber:bot Code.
button = dictionary['button'] # added
These lines were added to respond to the button values by lowering/opening or closing/lifting the Gripper paddles.
if button == 'B': # added bot(16).servo_angle(30) # added Gripper close & lift elif button == 'A': # added bot(16).servo_angle(150) # added Gripper lower & open