This video looked at the claim that computers are mostly large collections of switches. While true, that claim doesn't get you very far. What really matters is what the switches are connected to, and how they are activated.
A switch that can be directly accessed by the programmer is called a bit, and eight bits are grouped together to make a byte.
One of the bytes in the ATmega328/P is called PORTB. Each bit in that byte can connect to one of the external pins of the chip. Two of the pins can't be used on the Arduino because they're dedicated to the 16 MHz crystal oscillator. The other 6 pins go to pins 8 to 13 on the Arduino, which connect to the LEDs on the ThinkerShield. So by playing with the bit values in PORTB, we can control whether the ThinkerShield LEDs are on or off.
0 MOV #0b100001,PORTB 1 WAIT 5000 2 MOV #0b000000,PORTB 3 WAIT 5000 4 JMP 0
Turns the top and bottom LEDs on for half a second, then off for half a second, and repeats.
This very simple program demonstrates how the processor deals with all programs. It just carries out the instruction at hand, then moves on to the next instruction. Only jump instructions can change where the next instruction comes from.
Besides the three low LEDs alternating with the three high ones, you might like to try some other experiments.
Experiment with the value in the WAIT instructions (using the same value in both) to work out how long this needs to be for you to notice the flicker. I find my threshold at a value around 130. That works out at about 1/38th of a second, so I'm not a high performer (I'll blame the ThinkerShield LEDs).
This simple control of on and off intervals is given the very imposing name of Pulse Width Modulation (PWM). We'll do some more with it in later videos.
255 WAIT 10000 RUN 255you can see that it will delay for a full second, but then what? There's no slot 256, so where will it get the next instruction? Try it. This mightn't make sense right now, but there is an explanation in the next video.