Okay, time to get some traction on this project. Many MC projects will
start with “HELLO WORLD” (called HW from this point on)examples. The reason
for this, is it lets you know your circuit (electronic project) is up and
running properly with a minimum amount of effort. Although the basic stamp
has its own HW example using the serial programming connection, my project
is a little more simplistic? we are simply going to get our LEDs blinking
first, then we are going to add our buttons so that when you press the red
button the red LED blinks, when you press the green button the Green LED
blinks, if you press neither the amber LED blinks and if you press all 3
all three blink. Later down the line we will adapt these routines into our
final project. Thinking ahead, we might as well throw in sound as it will
be great for causing the delay we need to get a rough one second interval.
Unfortunately the stamp does not have a means of doing an internal real
time clock, so we will have to do trial and error with the code to generate
a rough 1 second loop time. First things first, you can add one component
at time and get them running using examples in the book. I’m going to go
ahead and build up all the components I mentioned above. There is a nice
free schematic/circuit board program that is free from ExpressPCB.com. For
some projects they are too simple; but, for this project they will work
fine. Using the program I combined the parts from the various chapters in
the manual to create what we are going to put together so far. I’ll try to
stick as best I can to the symbols they use in the book.

Now, to help me visualize where everything is
going to fit on the board, I placed everything on the bread board with the
exception of the speaker – which I will add shortly. There is not a ton of
space to utilize here, so I had to squeeze The LEDs in a tight
configuration close to where they patch in to the microcontroller through
the side female header board (black thingie full of holes marked X4
P15-P0). The picture below has been enhanced a bit (since I have a camera
that will not focus up close on hand) so you can see how I plugged in the
LEDs with the Resistors standin on their sides. I like to keep things short
and tight so as to avoid shorting things – since we will be transferring
everything to a second board eventually, you don’t really need to cut the
leads short and run the wires the way I do…you can run them on long leads
in any configuration you want – just be careful that the legs (leads) don’t
touch unless they are supposed to. Anyway, As you can see from the picture,
I cut the LED’s negative leads (leg on the flat side of the LED) short and
plugged them all into one row on the board to save space. The black wire
leaving that row attaches it to Vss (Ground).

Now that we have
the LEDs in place…lets make a simple routine that will turn them on then
off one at a time. This will let us know they are hooked up correctly. If
you don’t have the manual and just want to follow learn, there is a GREAT
documentation power point presentation at:
<a href=”
http://www.parallax.com/tabid/564/Default.aspx”>http://www.parallax.com/tabid/564/Default.aspx</a>
(Warning you may need Microsoft windows power point to run these)
You can
start with the file ” WAM? Chapter 1: Getting Started” – this will give you
an overview of the system.
The section “WAM? Chapter 2: Lights on – Lights
off” and “WAM? Chapter 3 Digital Input -Pushbuttons”.
Finally the section “WAM?
Chapter 8: Frequency and Sound” has the meat of information that you will
need for when we add sound.
Here is the first clip of code:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
‘ CODE: DOMINATION TOWERS 1.0
‘ {$STAMP BS2}
‘ {$PBASIC 2.5}
‘ DEBUG “Domination Tower Intialization”
DO ‘ Test the LEDs to ensure each lites up properly.
HIGH 5
PAUSE 300
LOW 5
HIGH 6
PAUSE 300
LOW 6
HIGH 7
PAUSE 300
LOW 7
LOOP ‘ Go back to the DO and loop over and over forever
‘end of program
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is a very, very simple program. It actually starts at the DO, which marks the
beginning of a loop. It then sets the voltage HIGH then LOW for each of the
pins with an LED on them. The PAUSE stalls the process for a number of microseconds so the User can actually see the light blink. Lines starting with a ‘ are comments which are
there just for you and me as a way to leave notes of what we are doing at
that point in the code. With the exception of the compiler directives which
have the {} brackets on them, these lines are used by the compiler but ignored by the program. The program only shows us the unit is up and running and all the LEDs are wired correctly.
Next
step is to add the pushbuttons…for this we turn to chapter 3. Page 84 has
the jist of what we are trying to accomplish. So I’m going to add the
buttons and then modify our program. I’ve kept the original code as its a good way to ensure that the LEDs are plugged in and working. Added to it is routines that check the pushbuttons and turns on lights appropriately to let the user know the circuit is responding to the button press. This is called giving the user ‘feedback’. Feedback is VERY important for humans that have a tendency to beat technology up when they think its not responding to them – always give feedback of some kind. It also helps you troubleshoot (figure out what is going wrong) when things are not working properly.
The new code:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
‘CODE: DOMINATION TOWERS 1.1
‘ {$STAMPBS2}
‘ {$PBASIC 2.5}
‘ DEBUG “Domination Tower Intialization”
‘————————————————
‘ Test the LEDs to ensure each lites up properly.
HIGH 5
PAUSE 300
LOW 5
HIGH 6
PAUSE 300
LOW 6
HIGH 7
PAUSE 300
LOW 7
‘————————————————
DO ‘ Start Main loop
IF (IN3 = 1) THEN ‘ if the button attached to IO 3 is High (>1.5V) then
HIGH 5 ‘ Turn on LED on Output 5 (RED LED)
PAUSE 50 ‘Wait for a fraction of a second
ELSEIF (IN4 = 1) THEN ’ if the above wasn’t true then check if the other
‘button is ‘ pressed if it’ is then
HIGH 7 ‘Turn on the LED on Output 7 (GREEN LED)
PAUSE 50 ’ Wait for a fraction of a second
ELSE ‘ If none of the above is true then
HIGH 6 ‘ Turn on the LED on Output 6 (AMBER LED)
PAUSE 50 ‘ Wait for a fraction of a second
ENDIF ‘ We are done checking buttons
LOW 5 ‘ Turn off all the LEDs
LOW 6
LOW 7
PAUSE 50 ’ Wait for a fraction of a second
LOOP ‘ Go back to the DO and loop over and over forever
‘ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Next time I update this posting I will add sound and modify the program to include it as well as add functionality that handles when both buttons are pressed at the same time.