|Tutorial: Blinky Light|
Turn on your Propeller Platform and connect it to your computer. Grab an LED and breadboard and wire up the following circuit;
The hookup wire connects to the socket marked 'GND' on the Propeller Platform, then to the shorter lead on the LED. The longer lead on the LED connects to the resistor, then to P0 on the Propeller Platform.
The shorter lead on the LED is the negative lead. The longer lead is positive. Current flows from power to ground, so the longer lead connects to the power source.
Now, open up the Propeller Tool. Ready for your first program? Here it is:
Take the program above, put it into the Propeller tool and hit F10. It will quickly compile and load into the Propeller. The code will blink an LED connected to P0 every other second (1/2 Hertz) forever.
Below is a video tutorial on the program;
Let's also break down each line to understand what it's doing
Spin is organized into blocks;
There are 2 more blocks, DAT and OBJ, but we'll skip those for now - OBJ is useful when incorporating someone else's code, and DAT is another place to hold variables, it's also where you put assembly code (if you want to use it).
dira :=1Every pin on the Propeller can be set to an input or an output. When the Prop boots up, each pin is set as an input, so we'll need to set P0 to an output.
To set P0 as an output, we'll change the value of dira to 1. The := is an assignment operator in spin. Can you guess how you'd set P10 to an output? dira := 1. You can also change a range of pins with a single command. To change P0,P1,P2, and P3, just use dira[0..3] := 1.
repeatrepeat tells the Propeller to run a block of code multiple times. You can specify a repeat condition (repeat i from 1 to 100) or just repeat forever by not specifying anything else. This repeat block will repeat forever.
Code to be repeated is delineated by tabs. Note the soft gray lines under the repeat block? The Propeller Tool put those gray lines there to show you what code is in the repeat loop.
outa := 1
outa tells the propeller to connect the pin to ground or to V+. outa works just like dira, you can set the output of a single pin (outa := 1) or a group of pins (outa[0..3] := 1). Note that outa is only meaningful if the pin has been switched to an output with dira.