![Parallax 29157 Скачать руководство пользователя страница 18](http://html1.mh-extra.com/html/parallax/29157/29157_manual_754483018.webp)
Parallax, Inc. • BASIC Stamp HomeWork Board ver 1.1
Page 18
The first thing we'll do is create a report on what's happening. We start with
DEBUG
Home which causes the
DEBUG
cursor [not visible] to move to the first row, first column of the screen. Next we'll print out the values of
blinkVal
and
blinkBit
using the
DEC
modifier to specify their display as decimal numbers. If we leave
DEC
out, the
DEBUG
window with attempt to display the characters defined by their current value – that's not what we want.
Then we'll print
blinkVal
again, this time using the
BIN
modifier so that we see it as a binary value. Now we can
see what's going on inside of
blinkVal
. As its value changes we'll be able to see the corresponding bits change.
Finally, we'll use the value of
blinkBit
to position a pointer under the current
blinkVal
bit that is controlling the LED.
This line of code uses the
REP
modifier to repeat a character. In our case we going to repeat a space. We
position it under the proper bit by subtracting the current
blinkBit
value from seven. When
blinkBit
is zero, this line
will print seven spaces, then the pointer. When
blinkBit
is one, it will print six spaces then the pointer. You get the
idea.
Now that we know what's going on, let's make it happen. The line of code that actually controls the LED uses
another advanced feature of the PBASIC language: variable modifiers. In this program we're using
LowBit
.
Without an index (the value in parenthesis),
LowBit
will always point to bit zero of a variable. Since we want to
point at all bits, starting with zero and ending with seven, we will use the index. The index value is and offset into
the variable from bit zero. So,
LowBit(0)
points to bit zero,
LowBit(1)
points to bit one and so on.
And, finally, there is a very short
PAUSE
so we can see the LED blink when we’re on the low bits. In actuality,
sending the report to the
DEBUG
screen takes some time as well and contributes to the overall loop timing.
Wow, that was quite and interesting program for simply blinking an LED, wasn't it. If you're still not quite sure how
it works, don't worry, it will set in with time and we will review these techniques in other projects.
Test Your Knowledge
If the forward voltage of the LED is 1.7 volts, what is the current through the LED with the total series resistance
of 440 ohms (220 + 220)?