The Propeller microcontroller has 32 input/output pins, or I/O pins, that are designed to interact with other circuits. The circuits in this example are built into the Propeller Activity Board's printed circuit board, but later examples' circuits are constructed using the white breadboard prototyping area. This tutorial can be done using a Propeller FLiP module as well.
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 (original or WX version), Propeller FLiP, and the Propeller Board of Education.
Note: if you are using a different Propeller board, build the equivalent circuit using the schematic.
Now, 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. 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] http://learn.parallax.com/propeller-c-set-simpleide
[2] http://learn.parallax.com/propeller-c-start-simple