- Turn power off at the switch on the board.
- Use your multimeter to find the common ground on the resistor network. This will be one of the outside pins, and when combined with any other pin it will have half the resistance (.99 k ohm) of any other two-pin combinations.
| Common ground means that all the resistors share a single ground plane. |
- Connect the ground pin of the resistor with the ground on the Board using the jumper wire.
- Place the anode ends of the LEDs in line with the non-common pins of the resistor, as in Figure 8-12. Be sure not to let the leads of the LEDs touch.
| Back view of the circuit | PROGRAMMING THE PROJECT Memory Your BS2 has two kinds of memory. One is called RAM, for random access memory, which you can write and erase very rapidly. The BS2 has 32 bytes of RAM memory. When you power down the stamp this memory disappears. The electronically programmable random access memory (EPROM) chip can have data written to and erased from its memory. When you power down the BS2 the data and programs you have downloaded into the EPROM are saved and will be there when you turn the stamp back on again. To erase the EPROM, simply write over the data previously stored. DIRS = %1111111 With DIRS, you can use a single command to define which pins (0-15) are outputs and which pins are inputs. When you use DIRS in your code, each bit you use represents a pin's direction. A low (0) bit changes the corresponding input/output (I/O) pin to an input direction, and a high (1) bit changes the corresponding I/O pin to an output direction. In this example, DIRS = %11111111, we have told the stamp that pins 0-7 are all defined as output pins. If you wanted to write to all sixteen pins with 8 pins as output and 8 pins as input, the line of code would look like this: DIRS = %1111111100000000. This will make pins 0-7 outputs and pins 8-15 inputs. Now you are ready to tell the pins if they should go high or low and to turn your LEDs on or off by doing so. OUTS=%1010101 OUTS The OUTS command controls the logical state of each pin. OUTS allows you to set the pins high (1) at 5 volts or low (0) at 0 volts. Introductory Example Program: Setting the Pin High ‘ {$STAMP BS2}DIRS = %11111111 ‘sets pins 0-7 as outputs only TOP: ‘this is a label or marker in the program OUTS =%10101010 ‘this sets pins 1, 3, 5, 7 to high ‘and 2,4,6,8 to low PAUSE 600 ‘stops the code for .6 seconds OUTS =%01010101 ‘sets pins 1,3,5,7 to low and ‘2,4,6,8 to high PAUSE 600 ‘stops the code for .6 seconds GOTO TOP Now it’s your turn: - Enter the program above.
- Now vary the pause between 20 milliseconds and 2000 milliseconds.
- What do you notice? ______________________________________
In the program below notice that where the 1s are located the light will turn on, which is a visual way to associate turning the pin on or high. DIRS = %11111111 ‘sets pins 0-7 as outputs only. TOP: OUTS =%01111111 “Set pin number 8 high and 1-7 low (con) PAUSE 100 OUTS =%10111111 PAUSE 100 OUTS =%01011111 PAUSE 100 OUTS =%11101111 PAUSE 100 OUTS =%11110111 PAUSE 100 OUTS =%11111011 PAUSE 100 OUTS =%11111101 PAUSE 100 OUTS =%11111110 PAUSE 100 OUTS =%11111101 PAUSE 100 OUTS =%11111011 PAUSE 100 OUTS =%11110111 PAUSE 100 OUTS =%11101111 PAUSE 100 OUTS =%11011111 PAUSE 100 OUTS =%00111111 PAUSE 100 GOTO top Wow, this has many lines of repetitious code! In the next experiment we will be using a command set called the FOR NEXT LOOP, which makes for much less typing. The FOR NEXT LOOP will be more thoroughly explained in Chapter 13. For now, just enjoy the pattern. The next pattern of programming is interesting because it begins with the LEDs being perceived as a single flashing object, and then as the flashing slows, they are visually differentiated as separate blinks. This kind of visual motion can be exploited in an art object.
|