Now we're gonna program it.
[Excerpted from ROBOT BRAINS with Rick Galinson] I'm gonna plug power in
and the program that was previously in the chip
is still running, so it's running that one LED.
Now we're gonna go to the computer screen,
and we're gonna add--
We have one on pin four,
gonna add one on pin ten,
and now we'll make those go.... LOW,
on pin four,
LOW on pin ten.
Now these are out order,
or they could be out of order,
and it doesn't matter
because the processing speed is so quick
that you will never see this.
Which one turned on first,
which one turned on second.
So I'll load this now. There it goes.
Now all three LEDS are going together.
Now we could change the order that these go,
by changing a couple of components
and we'll make it go a little faster
so it's a little more... Interesting.
And we're gonna take a couple of these down lower,
just copy and paste,
we'll turn them all in together.
And then...
Uh, let's try that, what's that gonna do?
Wanted it-- They're gonna turn on together,
and then... Turn off at different speeds.
So you can set a sequence.
And if you change the code accordingly,
you could have any LED turn on for any duration.
Other LEDs changing their cycle, their speeds,
their flicker effect.
Let's see how fast we can get these guys going.
Let's make this a tenth of a second, on and off.
Mm, okay.
So now it's going much faster,
we can go even faster than that.
Let's go twice as fast.
Couple changes of code...
Boom. Now it's getting exciting.
And like I said before we can add external chips
in the-- On this proto board,
which would run hundreds of LEDs
if you chose to do that.
Okay, so here we are on the software side
of the LED display.
And we're gonna run through line by line
what's been happening here.
The first line is telling the processor,
or the environment,
that I'm using a BASIC Stamp 2SX chip,
which happens to be the blue one.
The green one is the BASIC Stamp 2,
and you see a little, uh...
Pop-down window appear,
telling you the name, the label,
of each model,
so in case you can't remember it
they show you right there.
So you click on that. It pops this in here.
And what I think it's doing is
it's loading libraries and...
All the background stuff
that the computer chip needs to do to function
that you don't need to know about.
Just click on that and you're done.
This next line here
is the BASIC Stamp 2.5 language.
These are all just versions, you know.
Every software goes through versions 1.0, 1.2...
That's all that is.
Again, it's libraries, it's look up tables...
All the details that you'll never have to know.
But just click on that so the computer knows
you're using the most modern language,
and all the functions that they have.
I'm gonna go down here.
I have zero variables declared.
I have zero constants. I have zero notes.
Nothing is written up here,
it's a very simple program.
I have called it "main", 'cause that's a...
A habit I've learned when I started,
most people choose 'main'
as their original starting block.
It can be any word you want,
as long as it's not a key word
that is one of the commands used in the language.
Like these down here, it says 'HIGH'.
That means you're turning the pin to high voltage,
or five volts.
You can't use that as this word here,
or anywhere else.
They're kind of dedicated.
'PAUSE' is another command word you cannot use.
'LOW'... All those things.
'GOTO' down here, and any of that comes up blue,
or that's in the manual,
are reserved words for the language.
So we don't let in any complicated,
you know... Misconceptions there.
So we've chosen main here as just a label,
to a point in the program
where we can jump back to.
If you have several of these labels
down lower in the program,
if it's a more complicated program,
you could jump to any point in the program.
Kind of like a number line.
In other programming languages
you have number lines, along the side--
The left side of the program you've written.
Line 53, 54, 55, and you can go to those lines.
Or reference things.
That's just a simple name, anything will do.
This first line here, 'HIGH', is a...
Program reserve word.
It's one of the functions
that the computer understands. You write 'HIGH',
it's now expecting to see a number,
which corresponds to one of the 16 pins
on the BASIC Stamp.
Any one of these pins can be used to run LEDs.
Right below it we've chosen another one, four.
And now we've done also pin ten here as well.
You could have all 16 go 'HIGH',
and all 16 lights would light up together.
Another reserve word, one of the commands
is 'PAUSE', and like you would imagine
since this is very much like English,
it's just gonna 'PAUSE'
for a certain duration of time
and you choose that number.
So this is 50 milliseconds.
So a 20th of a second.
So here we have 'LOW',
and the light would turn off on number six.
Then four and ten would still be on,
because they've not gotten the command
to turn off yet.
You pause for another 50 milliseconds,
and then it-- Four goes 'LOW',
and ten goes 'LOW',
and the lights are all turned off.
And it 'PAUSE's again,
then it goes to the next line.
A computer runs in a very serial fashion,
where it goes from one line of code to the next,
to the next, to the next.
And it, uh-- Branches are occurring,
if it jumps from one decision to another,
based on how you program the code.
And this last line here,
you have a 'GOTO' statement,
and we have chosen 'main',
so at-- When it hits this line and executes it,
it will jump back up to the top,
where it says 'main',
and then start all over.
And it will do this forever,
until you turn the power off, or reset the chip.
[SUBSCRIBE AT www.stanwinstonschool.com for full access to this course]
[SUBSCRIBE AT www.stanwinstonschool.com & over 450+hours of Education]