You are here: Spin Programming Tutorial > Spin Lesson 2 > Our First Object

Our First Object

Spin Exercise 2-1: Output.spin

The following is a simple object, written in Spin, that will toggle an I/O pin high and low repeatedly. 

PUB Toggle
  dira[16]~~
  repeat
    !outa[16]
    waitcnt(3_000_000 + cnt)

 

While indentation is critical, capitalization is not.  Propeller code is not case-sensitive.  However, throughout this book, reserved words appear in bold capital letters, except in code snippets and excerpts, to help you become familiar with them. 

If the program you entered is syntactically correct and the Propeller chip is properly powered and connected to the PC, you should see the Propeller Communication dialog appear momentarily on the screen, and now the LED on I/O pin 16 of the Propeller chip should be blinking about twice per second. 

Propeller Communication Dialog

 

What really happened was probably too fast to see because the example program we entered is so small.  When you pressed F10 it caused the Propeller Tool to compile the source code you entered and turn it into a Propeller Application.  The Propeller Tool then searched for a Propeller chip connected to the PC and downloaded the application into its RAM.  Finally, the Propeller started running the application from RAM, blinking the LED on I/O pin 16.

Propeller Help Version 1.1

Copyright © Parallax Inc.

5/13/2009