Your Activity Board WX version has two built-in lights, near the bottom-right corner of the board. These tiny light-emitting diodes (LEDs) are already electrically connected to I/O pins P26 and P27. These LEDs are helpful when developing applications that use sensors. The idea is to write your program so that if a sensor is activated, an LED lights up to give you, the roboticist, a quick visual cue that the sensor is actually detecting something.
We'll experiment with the "O" (output) feature of an I/O pin by programming the Propeller to use an I/O pin to turn a light on and off.
Our light circuit is already built into the Propeller Activity Board WX. Here is what the schematic looks like for this circuit:
See the Schematic Symbols reference. [1]
Let’s try running an example program that blinks the LED light connected to P26.
The function call high(26) sets the Propeller chip's P26 I/O pin to output-high, which connects the pin to its 3.3 V supply. 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, pause(100) makes the program do nothing for 100 ms, which keeps the light on for 1/10 of a second.
Next, low(26) sets P26 to output-low, which connects the pin to its 0 V ground supply voltage instead. This takes away the electrical pressure, so the current stops flowing through the circuit and the light turns off. Another pause(100) makes the light stay off for 1/10 of a second.
Those four commands are in a code block in a while(1) loop, which repeats endlessly, so the light keeps blinking.
/* Blink Light.c Blink light circuit connected to P26. */ #include "simpletools.h" // Include simpletools int main() // main function { while(1) // Endless loop { high(26); // Set P26 I/O pin high pause(100); // Wait 1/10 second low(26); // Set P26 I/O pin low pause(100); // Wait another 1/10 second } }
The simpletools library has lots of useful functions for controlling and monitoring circuits; high, low, and pause are just three examples. Click the SimpleIDE Help menu and choose Simple Library Reference to see a link to the simpletools library's functions.
You can make the light blink faster by reducing the pause function’s parameter value. For example, to blink the light twice as fast, just reduce the pauses to half as long.
Try controlling the P27 light along with the P26 light.
Links
[1] https://learn.parallax.com/support/reference/schematic-symbols