Hey Eric:
1.) You've pretty much got it right. The label that gets called is determined by the value of M1. If M1=0, then the "zeroth" element of the array gets called. If M1=1, then the first element of the array gets called. And so on. This type of jump based on register value is described
here
.
2.) I'm not sure offhand if there is a higher level way to write data to a port on an Arduino. The digital write command is geared toward writing to a single pin. In order to write to the port (or a group of pins) all at once you need to do some lower level port manipulation. One option might be to extract one bit at time from your variable and write to output pins individually. That is, you could extract bit0 from your variable and write it to pin0, then extract bit1 and write it to pin1, and so on. This could be done at a higher level, I think.
3.) In the Arduino code, the reason we clear the bits before writing to them has to do with the way the values are written to the pins. Let's look at how we write the tens value to Port B as an example. Since we are only using the lower four bits on port B we don't want to write to the whole port all at one. Doing so would clobber the upper four bits that might be used for something somewhere else in the program. So instead of writing the whole port all at once, we use a bitwise AND to clear the lower four bits.
PORTB &= 0xF0; // clear the lower four bits of Port B
ANDing the port with hex value F0 (same as binary 11110000) forces the lower four bits to zero. We then do a bitwise OR to write the tens value to the lower four bits:
PORTB |= tens; // write the tens values to Port B
The bitwise OR sets the individual bits in the port to match the bits in the tens variable. So, for example, if tens is equal to 9 (binary 1001), then the lower for bits of the port get set to 1001.
4.) To register a different temperature range, you would need a sensor to measure that range and you might need to scale the reading differently. Right now this example project uses a total of eight bits to relay the temperature, for a total of 256 combinations. This example project is essentially arranged to register temperatures from 0 to 109 degrees (in steps of 1 degree). You could just as well register temperatures in a different range and scale, for example 0 to 1000 (in steps of 10).