You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
In this new progra, the A array stores the light patterns, while th<br />
M array stores the time intervals.<br />
Step 1<br />
So far, the computer has served only as a sequencer, generati<br />
the proper lamp patterns and time delays. In this step, some contr<br />
steps will be added to the traffic-light control program.<br />
The traffic on Main Street is usually heavy, so the normal mod<br />
for the traffic light should be green on Main and red on Elm.<br />
program should be able to detect a single car waiting on Elm,<br />
that it may be given the green light. However, Main Street m<br />
be given at least 30 seconds of "green time," before any cars a<br />
sensed on Elm Street. This means that every car waiting on El<br />
Street will not automatically trigger a green-on-Elm sequence. T<br />
make things even more interesting, there is a sensor on Main Stree<br />
too. If five or more cars are waiting on Main Street at a red ligh<br />
Main Street will be given the green light, and the cars on Elm wi<br />
have to wait.<br />
In order to program this, you may wish to draw a simple flowch<br />
of the problem. An input port could be used to simulate the two road<br />
sensors, but to teach you a bit more about the Apple, the keyboard<br />
·<br />
will be used instead.<br />
The keyboard uses two memory addresses for control. Address<br />
49152 contains the keyboard data, and address 49168 is used as a<br />
flag-clear pulse output.<br />
Enter the following program into your computer and run it:<br />
2000 PRINT PEEK(49152): GOTO 2000<br />
Press some of the keys on the keyboard and note what happens<br />
the display. What do you observe<br />
There is a new decimal value displayed whenever a new key is<br />
pressed, and the value continues to be displayed until a new key<br />
is actuated. Thus, the information at input port 49152 represents the<br />
code of the last key that was pressed.<br />
Step S<br />
We would like to have the computer input a value from the keyboard<br />
input port only when a key has been pressed. To do this, you<br />
must use the keyboard flag bit, which is bit D7 at input port 49152.<br />
If this bit is a logic zero, all values from this port will be less than 128.<br />
If this bit is a logic one, the values will be 128 or greater, up to 255.