Make Electronics

(nextflipdebug2) #1
What Next? 303

Experiment 34: Hardware Meets Software

Editing


What if you want to change the program? No problem! Use the Programming
Editor to change one of the lines in the program. Substitute 100 instead of
1000 milliseconds, for instance. (The pause command can be followed by any
number up to 65535.) In your program, don’t use a thousands comma in any
of the numbers that you specify.


Plug the USB cable into the breadboard again, hit the Program button on the
screen, and the new version of the program will be automatically downloaded
to the chip, overwriting the old version.


What if you want to save the program for future use? Just go to the File menu
in the Programming Editor and save the program onto your computer’s hard
drive. Because the PICAXE uses a variant of the BASIC computer language, it
adds a .bas filename extension.


Simulation


If you make a simple typing error, the Programming Editor will find it and stop
you from downloading your program. It will leave you to figure out how to fix
the line that contains the error.


Even if all the statements in your program are correctly typed, it’s a good idea
to run a simulation of what they’ll do, before you download them. This is easily
done: click the “simulate” button on the menu bar of the Programming Editor.
A new window will open, displaying a diagrammatic view of the PICAXE chip
and showing you the states of its pins. (Note that if you use very short pause
commands, the simulation won’t run fast enough to display the time accu-
rately.) A simulation screenshot is shown in Figure 5-140.


The >> button at the bottom-right corner of the simulation window will open
up a list of all the variables in your program. So far, it doesn’t have any vari-
ables, but it soon will. All the zeros on the righthand side are binary numbers,
which you can ignore for now.


Figure 5-140. This screenshot shows the simulation window that
can be opened in the Program Editor to test program code before it
is downloaded to the chip. The values of variables are shown in the
section on the right. The pin states are shown on the left.

You’ll need to check the second
part of the PICAXE documentation,
which contains all the programming
statements and their correct syntax.
At the time of writing, this is stored
at http://www.rev-ed.co.uk/docs/
picaxe_manual2.pdf.
Free download pdf