So Sergey got into the Christmas holiday spirit.
And he's like, let's do a bonus tutorial on the microcontroller.
So if you're watching this in December, happy holidays, Merry Christmas, all that jazz.
If not, well, it can't be more than 12 months away from that time.
So he was looking on Thingiverse and he found a cool little printable tree that you can
put lights into and thought, "What would be fun would be to make something with our PIC10F200
that makes lights race up and down.
And so one of the interesting things is is on this PIC10F200, you know that we only have
three GPIO.
But we can control up to six LEDs with these and that is through the magic of charlieplexing.
So on this bonus tutorial, we're not going to learn any new commands, anything like that
if you've watched up to tutorial seven, then you should know everything you need to do
this, but we are going to learn a little bit new hardware.
So the way that you do charlieplexing is you take advantage of the fact that a GPIO can
be one of three states.
It can be high, low or what they call high Z or high impedance.
And when it's high Z or high impedance, it doesn't matter what the other pin is, is your
if you're trying to create a circuit, because you're not going to be able to get any current
flow through that high Z pin.
So by taking that and taking the fact that diodes can operate in one direction and not
the other, you take your diodes, you can flip them so that if you have a high voltage on
one side and not on the other, one of the LEDs will turn on but not the other.
And then you flip it and then the other LED is on.
And then you do this with multiple pins by making it so that between the high low and
the high Z of the six leds, only one is on at a time.
So we have this table and it shows exactly the setups that you need to have to turn on
what according to our schematic is LED one through six and notice that it's a very specific
configuration.
If you go outside of these states, you're going to get some weird and erratic behavior
and we aren't responsible for the blowing up of your circuit.
Just kidding, it won't blow up but you will get some weird and erratic stuff.
So, with this table, you can see exactly what you need to do to turn on each one of these
LEDs.
And let's go back to that schematic really quick.
And you can see how at first, this looks a little bit confusing, but you have these six
LEDs and you see three pairs of them and again, all of the LEDs are backwards from each other.
And then you also notice that with these three pairs, all of them are sharing nodes with
another pair.
So sets LED 1, LED 2, they are connected with LEDs 5 and 6 on one side and LED 3 and 4 on
the other side.
Whereas LED 3 and 4 is connected with LED 1 and 2 on one side and LED 5 and 6.
On the other side LED 5 and 6 are obviously connected.
So this is a very specific way of setting it up.
And frankly, as I was setting this up on the breadboard, I was reminded of our breadboard
tutorial and the council I gave of being clean and making sure that you do everything right
so you don't have any accidental shorts and thinking wow, I'm terrible at this because
it works.
But it's not pretty and it is a little bit touchy if I move some things.
I've got some issues.
So it is a bit of a challenge put together, please do a better job than I do.
I don't know why I just struggle with making breadboards look decent.
But this is all you need.
So with this background, and we can see this more in practice.
And frankly, if you want to learn more, just go to Wikipedia about Charlieplexing there's
a lot of good information.
But really, the essence of it is high, low, high Z.
Let's jump right into the code.
And again, this is not going to be anything new.
Anything that you haven't seen before lines one through seven is your typical, setting
up some numbers, getting the delay variables, basically prepping for the code itself.
And then we initialize things by enabling the GPIO and then setting some as inputs,
some outputs.
And then we get into the actual loop itself, which is just 14 through 35.
And you'll notice all of these are very, very straightforward.
It's move literal one, move literal to working register one, call LIGHT_LED, move literal
to working register two, call LIGHT_LED, and it does that from one to six and then back
down to two.
All you're doing is basically putting a number in that working register and then calling
the light LED subroutine.
And that subroutine looks in the working register to figure out exactly what LED should be lit
up, and then it lights it up.
So that LIGHT_LED subroutine is down at 100.
And so it's basically taking that working register, putting it into the LED register
and then selecting the LED based off of that, calling the delay because otherwise this is
going to run too fast for you to be able to see anything, and then you go back and you
start over again.
So again, very, very, very simple.
So as we go and we do the Select LED, this is the most complicated portion of the entire
program and it's not even that complicated.
So in line 52, you have the Decrement F Skip If Zero and you decrement the register LED.
N,ow if you wanted to light up LED 1, you would have had LED 1 in there, it would be
decremented to zero sense it is zero, you would then skip line 53 and turn on that led
using lines 54 through 57.
And then skip, get out of the subroutine with that return literal to W zero.
Now, if that is not zero, because let's say you wanted to do two, then that two minus
one is going to give you 1.
That's not zero, so you don't skip line 53, you jumped down to line 59.
And then in life 59, you do the exact same thing, you decrement by one, if it's zero,
great, that means that you're in the right area, you skip over that GOTO command, you
turn on that led, and then you jump out of the sub routine, but if it is above zero,
then you keep on going down.
And that's all you do.
So it's kind of an ingenious way.
I'm actually pretty happy with the way Sergey put this together.
I think it's really cool.
The way you can just take it and say it's this - skip, skip.
Okay, this is the one we want just by decrementing it through and through.
So this is, to me, a unique feature of assembly that you just don't see in other languages
because you can do direct comparisons so much easier.
But, and this is a very cool way to light up that led that you want and that's really
it.
I mean, literally, that's it.
Once you select the LED, you jump out, you call the delay.
So the lights on long enough, then you jump back into that top loop.
And you go to the next step and you light up the next LED.
And that's really it.
So even though this is 106 lines long, a huge amount of it is repeated text, repeated code,
and it's really straightforward.
So let's program this thing.
I'll show you my breadboard working in action and we will move on from there.
Okay, there we go.
So as you can see, it's going from one to six.
And because I have this setup all wonky, it basically is going here, oh boy, and then
jumps over here to finish up the six.
So it's just bouncing back and forth.
And again, you can change that pattern however you want.
It's very, very simple.
The way he put it up is just in that main loop.
You... yeah.
So, in the main loop from 14 to 35.
Just change those however you want.
So if you want it to be bouncing, you can just put that in manually.
So again, very, very straightforward.
And while this isn't super impressive, you can actually scale this up, you can have multiple
LEDs in there.
And again, if you want, you can go print something on Thingiverse.
And then make your own small circuit board and put this on there.
And it will do this forever and ever off of a little battery, you can make a Christmas
ornament, you can make some sort of cool ornament.
And then you can show people and say, Hey, I made this and it'd be something I can actually
hold.
Man, I love tangible stuff.
It's just amazing.
And it's just going to be a lot of fun.
So I'm glad that Sergey took the time to put this tutorial together.
And it's just a cool little example of yet another very simple thing you can do with
the PIC10F200.
As it is, thank you very much.
I hope you have a great day - have a Happy Holidays, Merry Christmas, Happy Kwanzaa,
Happy Hanukkah, all of those things or just have a fantastic December-January timeframe
and just enjoy taking any frustrations you have with the world out on your electronics
and not other people.
Hope you like this video.
We'll catch in the next one.