The cyber:bot board has a built-in Propeller microcontroller on its underside. The Propeller has 32 digital input/output pins, called I/O pins for short, that are designed to interact with circuits. These are referred to by number, P0 through P31.
Some of the I/O pins are connected to circuits built into the cyber:bot board, that your robot is already using. For example, P16 through P19 are connected to 3-pin headers, where the servo motors are plugged into P18 and P19. In this activity, we will use P20 and P21, which are connected to tiny built-in LED lights. Later on, we will build circuits on the breadboard, and connect them to the sockets alongside labeled P0–P15. Scripts sent to the micro:bit module can instruct the Propeller to interact with these built-in circuits.
We'll experiment with the "O" (output) feature of an I/O pin with a program to turn the built-in LED circuit on and off.
On the cyber:bot, it’s a small part just above the P20 label in the lower-right corner of your board.
# pin_20_blink from cyberbot import * while True: bot(20).write_digital(1) sleep(2000) bot(20).write_digital(0) sleep(1000)
The program begins with from cyberbot import *. This lets your script use bot(pin) functions from the cyberbot module, which send command codes to the Propeller microcontroller. From there, the Propeller uses its pre-programmed firmware to interact with circuits connected to its I/O pins.
The function call bot(20).write_digital(1) sets Propeller I/O pin P20 to "output high" which means it connects to its 3.3 V supply, as shown on the left side of the image below. The pin applies 3.3 V of electrical pressure to the LED circuit, causing electric current to pass through it and the light to turn on. After that, sleep(2000) makes the program do nothing for 2000 ms, which keeps the light on for 2 seconds.
Next, bot(20).write_digital(0). This sets P20 to output-low, which connects the pin to its 0 V ground supply voltage instead, as shown on the right side of the figure below. This takes away the electrical pressure, so the current stops flowing through the circuit and the light turns off. Another sleep(1000) makes the light stay off for one second.
Those four commands are in a code block in a while True: loop, which repeats endlessly, so the light keeps blinking.
You can change the light's blink rate by changing the sleep function’s us argument. For example, to make the light blink a lot faster, significantly reduce the sleep time.
# pin_20_blink_fast from cyberbot import * while True: bot(20).write_digital(1) sleep(50) bot(20).write_digital(0) sleep(50)
Expand your script to control the P21 light along with the P20 light.