www.nutsvolts.com/index.php?/magazine/article/november2010_NearSpace
NEAR SPACE
is set to 0 (false). Any button name can appear in quotes
after the is_key command. If the command is written
is_key m “up”, then the variable m is set to one only if
the last key pressed was the camera’s up key.
if k=1 then shoot
This is the standard if-then statement. If the variable k
was set to 1 (because the previous line of script set it to
one when the last button pressed was the remote button),
then the command shoot is executed. If variable k was not
the last button pressed, then the shoot command does
not take place. Associated with the if-then command is
else. The else command indicates what the script is
suppose to do if the conditional statement is not true. So,
for example:
if k=1 then shoot else goto no_go
Notice that a command follows the if-then-else
statement. More than one command can follow an
if-then-else. That makes the following script record an image,
increment a counter, and display the value of the counter
when a condition is valid (that is, k=1). When the
condition is invalid, it increments a different counter and
displays its value.
if k=1 then
shoot
n=n+1
print “image” n
else
k=k+1
print “fail” k
endif
shoot
The shoot command clicks the camera’s shutter. In
other words, the camera takes a picture. The shoot
command runs the camera through the focus process
before recording an image.
goto “loop”
Whether the camera took a picture or not, the next
line of script sends uBASIC to the label named loop. The
label begins with a colon in the script, but is referenced by
a goto or gosub command wrapped in quote marks.
end
Just like other versions of BASIC, end marks the last
line of the script. If uBASIC comes across this line, all
execution halts. The second script we’ll look at is a simple
intervalometer. This script is appropriate for a BalloonSat
that is not carrying a programmable flight computer. In the
old days (circa 2003!), students would build
intervalometers with 555 timer ICs. Now they can fly a
Canon camera and add this simple script to its SD card.
rem Modified by NearSys 3 Sept 2010
@title Intervalometer
:interval
for n=1 to 200
sleep 10000
shoot
next n
end
There are two new commands in this script.
for n=1 to 200
.
.
.
next n
sleep 10000
OTHER COMMANDS
uBASIC permits you to control all the functions of
your Canon camera like you were pressing its buttons.
Many readers have scrolled and clicked buttons on their
digital cameras before. These buttons have names that can
be referenced in a uBASIC script with the click command.
So, rather than setting up your camera by clicking a series
of buttons, you can load a script to do it for you. Here’s
how the syntax works:
click “up”
This command momentarily presses the up button.
The up button is the top button in the scroll button on
many cameras. The other three in the scroll button are
down, left, and right. The name of the button follows
the command click and is wrapped in quote marks. Now
click only presses the button for a moment. If a button
must be held down for other options to be selected,
then use the press command. So, for example, I might
press and hold the menu button so the up button can
activate a new feature that isn’t available while the
menu button is not held down. The syntax for the click,
press, and release commands are all the same, with the
name of the button wrapped in quote marks after the
command. The script for pressing and holding the menu
button while clicking the up button to bring up an option,
and then clicking the right button to select it would look
like this:
press “menu”
click “up”
click “right”
release “menu”
A few other buttons demonstrate the power of using CHDK.
November 2010 69