The \"traffic light\" (microprogramming) assignment. This assignment is intended
ID: 3602890 • Letter: T
Question
The "traffic light" (microprogramming) assignment.This assignment is intended to introduce you to the concept of microprogramming -- storing a sequence of zeros and ones in a ROM and sending synchronous signals to control something, be it traffic lights or a complex CPU. I am setting this gentle assignment as an introduction to the technique in the hope that it will help you to complete with success the three projects which replace the midterm.
1. Maintain the current timings as much as possible. You will see the sequence of lights as follows for the North-South/East-West traffic lights: Red/Red (longs for safetty), Red/Green (long), Red/Yellow (short), Red/Red (safety), Green/Red (long), Yellow/Red (short) and REPEAT. The walk/don't walk lights are nor programmed and will remain orange (don't walk). Fix this first. During the safety combination of Red/Red, they should remain orange (don't walk). However, when East-West has a green light, it is safe to turn on the North-South (walk) light by outputting a 1, whereupon it will turn white.
2. As a second task (not for additional credit, just part of the assignment) change the major sequence as in (1) to match the European system. The only change is this: The light about to go green is immediately preceeded by a short, single tick period where BOTH red AND yellow are lit as a signal to prepare to move. So, change the sequence to Red/Red (long safety), Red/Red_&_yellow (short), Red/Green (long), Red/Yellow (short), Red/Red (safety), Red_&_Yellow/Red (short), Green/Red (long), Yellow/Red (short) and REPEAT.
The counter will drive the address lines of the ROM through 16 addresses (0 through 15) and a byte of data will by output from each address. I suggest that you make a table with columns for (a) the address, (b) the required display in words, (c) the binary pattern required to make the display in (b), the two hexadecimal digits corresponding to the binary pattern. Be organized and this will not take long at all.
The "traffic light" (microprogramming) assignment.
This assignment is intended to introduce you to the concept of microprogramming -- storing a sequence of zeros and ones in a ROM and sending synchronous signals to control something, be it traffic lights or a complex CPU. I am setting this gentle assignment as an introduction to the technique in the hope that it will help you to complete with success the three projects which replace the midterm.
1. Maintain the current timings as much as possible. You will see the sequence of lights as follows for the North-South/East-West traffic lights: Red/Red (longs for safetty), Red/Green (long), Red/Yellow (short), Red/Red (safety), Green/Red (long), Yellow/Red (short) and REPEAT. The walk/don't walk lights are nor programmed and will remain orange (don't walk). Fix this first. During the safety combination of Red/Red, they should remain orange (don't walk). However, when East-West has a green light, it is safe to turn on the North-South (walk) light by outputting a 1, whereupon it will turn white.
2. As a second task (not for additional credit, just part of the assignment) change the major sequence as in (1) to match the European system. The only change is this: The light about to go green is immediately preceeded by a short, single tick period where BOTH red AND yellow are lit as a signal to prepare to move. So, change the sequence to Red/Red (long safety), Red/Red_&_yellow (short), Red/Green (long), Red/Yellow (short), Red/Red (safety), Red_&_Yellow/Red (short), Green/Red (long), Yellow/Red (short) and REPEAT.
The counter will drive the address lines of the ROM through 16 addresses (0 through 15) and a byte of data will by output from each address. I suggest that you make a table with columns for (a) the address, (b) the required display in words, (c) the binary pattern required to make the display in (b), the two hexadecimal digits corresponding to the binary pattern. Be organized and this will not take long at all.
The "traffic light" (microprogramming) assignment.
This assignment is intended to introduce you to the concept of microprogramming -- storing a sequence of zeros and ones in a ROM and sending synchronous signals to control something, be it traffic lights or a complex CPU. I am setting this gentle assignment as an introduction to the technique in the hope that it will help you to complete with success the three projects which replace the midterm.
1. Maintain the current timings as much as possible. You will see the sequence of lights as follows for the North-South/East-West traffic lights: Red/Red (longs for safetty), Red/Green (long), Red/Yellow (short), Red/Red (safety), Green/Red (long), Yellow/Red (short) and REPEAT. The walk/don't walk lights are nor programmed and will remain orange (don't walk). Fix this first. During the safety combination of Red/Red, they should remain orange (don't walk). However, when East-West has a green light, it is safe to turn on the North-South (walk) light by outputting a 1, whereupon it will turn white.
2. As a second task (not for additional credit, just part of the assignment) change the major sequence as in (1) to match the European system. The only change is this: The light about to go green is immediately preceeded by a short, single tick period where BOTH red AND yellow are lit as a signal to prepare to move. So, change the sequence to Red/Red (long safety), Red/Red_&_yellow (short), Red/Green (long), Red/Yellow (short), Red/Red (safety), Red_&_Yellow/Red (short), Green/Red (long), Yellow/Red (short) and REPEAT.
The counter will drive the address lines of the ROM through 16 addresses (0 through 15) and a byte of data will by output from each address. I suggest that you make a table with columns for (a) the address, (b) the required display in words, (c) the binary pattern required to make the display in (b), the two hexadecimal digits corresponding to the binary pattern. Be organized and this will not take long at all.
Explanation / Answer
int red = 10;
int yellow = 9;
int green = 8;
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop(){
changeLights();
delay(15000);
}
void changeLights(){
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
digitalWrite(yellow, HIGH);
delay(2000);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(3000);
}
void loop() {
if (digitalRead(button) == HIGH){
delay(15);
if (digitalRead(button) == HIGH) {
changeLights();
delay(15000);
}
}
}
int red1 = 10;
int yellow1 = 9;
int green1 = 8;
int red2 = 13;
int yellow2 = 12;
int green2 = 11;
void setup(){
pinMode(red1, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(green1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(green2, OUTPUT);
}
void changeLights(){
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
digitalWrite(yellow2, HIGH);
delay(5000);
digitalWrite(yellow1, LOW);
digitalWrite(red1, HIGH);
digitalWrite(yellow2, LOW);
digitalWrite(red2, LOW);
digitalWrite(green2, HIGH);
delay(5000);
digitalWrite(yellow1, HIGH);
digitalWrite(yellow2, HIGH);
digitalWrite(green2, LOW);
delay(3000);
digitalWrite(green1, HIGH);
digitalWrite(yellow1, LOW);
digitalWrite(red1, LOW);
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(5000);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.