can you see the google drive file?
//24948440
const int rgbRed = 3;
const int rgbGreen = 5;
const int pedestrianRed = 6;
const int pedestrianGreen = 7;
const int button = 8;
const int potPin = 0;
// 7 segment display pins
const int a = 13;
const int b = 12;
const int c = 11;
const int d = 10;
const int e = 9;
const int f = 2;
const int g = 4;
bool loopStarted = false;
bool wasButtonPressed = false; // Flag to check if the button was pressed during the loop
bool loopComplete = false; // Variable to track loop completion
unsigned long statusTime;
unsigned long currentTime = 0;
unsigned long lastBlink = 0;
unsigned long previousTime;
unsigned long lastDisplay = 0;
unsigned long buttonPressTime = 0;
unsigned long debounceDelay = 50;
unsigned long lastDebounceTime = 0;
int loopStep = 0;
String Status1 = "|TRAFFIC GREEN | PEDESTRIAN RED|";
String Status2 = "|TRAFFIC YELLOW | PEDESTRIAN RED|";
String Status3 = "|TRAFFIC RED | PEDESTRIAN RED|";
String Status4 = "|TRAFFIC RED | PEDESTRIAN GREEN|";
String Status5 = "|TRAFFIC RED | PEDESTRIAN RED FLASH|";
String currentStatus = "";
void setRgbColour(int rgbRedValue, int rgbGreenValue) {
analogWrite(rgbRed, rgbRedValue);
analogWrite(rgbGreen, rgbGreenValue);
}
void setPedestrianLights(int pedestrianRedValue, int pedestrianGreenValue) {
analogWrite(pedestrianRed, pedestrianRedValue);
analogWrite(pedestrianGreen, pedestrianGreenValue);
}
void waitForButtonPress() {
while (digitalRead(button) == HIGH) {
// Wait for the button to be pressed
}
while (digitalRead(button) == LOW) {
// Wait for the button to be released
}
}
void print9() {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
Serial.println("NINE");
}
void print8() {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
Serial.println("EIGHT");
}
void print7() {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
Serial.println("SEVEN");
}
void print6() {
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
Serial.println("SIX");
}
void print5() {
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
Serial.println("FIVE");
}
void print4() {
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
Serial.println("FOUR");
}
void print3() {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
Serial.println("THREE");
}
void print2() {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
Serial.println("TWO");
}
void print1() {
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
Serial.println("ONE");
}
void print0() {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
Serial.println("ZERO");
}
void printBlank() {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void setup() {
pinMode(rgbRed, OUTPUT);
pinMode(rgbGreen, OUTPUT);
pinMode(pedestrianRed, OUTPUT);
pinMode(pedestrianGreen, OUTPUT);
pinMode(button, INPUT);
pinMode(potPin, INPUT);
Serial.begin(9600);
setRgbColour(0, 255); // RGB to green
setPedestrianLights(255, 0); // Pedestrian red
currentStatus = Status1; // Initialise currentStatus with the first status
Serial.println("" + currentStatus);
waitForButtonPress(); // Wait for the button press to start the loop
statusTime = millis();
printBlank();
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void loop() {
int readButton = digitalRead(button);
if (readButton == HIGH && !loopStarted) {
Serial.println("|BUTTON HAS BEEN PRESSED|");
buttonPressTime = millis();
loopStarted = true; // Start the loop when the button is pressed
loopStep = 0; // Reset loopStep to start from the beginning
}
unsigned long currentTime = millis();
if (loopStarted) {
unsigned long elapsedTime = currentTime - buttonPressTime;
switch (loopStep) {
case 0: // Traffic Yellow, Pedestrian Red
if (elapsedTime >= 3000) {
Serial.println("" + Status2);
setRgbColour(255, 255);
setPedestrianLights(255, 0);
loopStep++;
previousTime = currentTime;
}
break;
case 1: // Traffic Red, Pedestrian Red
if (currentTime - previousTime >= 5000) {
Serial.println("" + Status3);
setRgbColour(255, 0);
setPedestrianLights(255, 0);
loopStep++;
previousTime = currentTime;
}
break;
case 2: // Traffic Red, Pedestrian Green
if (currentTime - previousTime >= 5000) {
Serial.println("" + Status4);
setRgbColour(255, 0);
setPedestrianLights(0, 255);
int nestedLoopStep2 = 0;
unsigned long nestedLoopStartTime2 = currentTime;
loopStep++;
print9();
if (currentTime - nestedLoopStartTime2 >= 1000) {
printBlank();
}
// Variables for the nested loop
while (nestedLoopStep2 < 5) {
if (currentTime - nestedLoopStartTime2 >= 1000) {
switch (nestedLoopStep2) {
case 0:
print8();
break;
case 1:
print7();
break;
case 2:
print6();
break;
case 3:
print5();
break;
}
nestedLoopStep2++; // Increment the nested loop step
nestedLoopStartTime2 = currentTime; // Reset the nested loop timer
}
currentTime = millis(); // Update the current time
}
previousTime = currentTime;
}
break;
case 3: // Traffic Red, Pedestrian Flashing Red
if (currentTime - previousTime <= 4000) {
Serial.println("" + Status5);
setRgbColour(255, 0);
setPedestrianLights(255, 0);
unsigned long startTime = currentTime;
unsigned long blinkInterval = 111; // Blink interval in milliseconds
bool pedestrianRedState = HIGH; // Initial state of the pedestrianRed LED
// Variables for the nested loop
int nestedLoopStep3 = 0;
unsigned long nestedLoopStartTime3 = currentTime;
while (currentTime - startTime <= 7000) {
if (currentTime - lastBlink >= blinkInterval) {
lastBlink = currentTime;
pedestrianRedState = !pedestrianRedState; // Toggle the pedestrianRed LED state
digitalWrite(pedestrianRed, pedestrianRedState); // Update the LED state
}
if (currentTime - nestedLoopStartTime3 >= 1000) {
switch (nestedLoopStep3) {
case 0:
print4();
break;
case 1:
print3();
break;
case 2:
print2();
break;
case 3:
print1();
break;
case 4:
print0();
break;
case 5:
printBlank();
break;
}
if (currentTime - lastBlink >= blinkInterval) {
lastBlink = currentTime;
pedestrianRedState = !pedestrianRedState; // Toggle the pedestrianRed LED state
digitalWrite(pedestrianRed, pedestrianRedState); // Update the LED state
}
lastBlink = currentTime;
// Toggle the state of the pedestrianRed LED
nestedLoopStep3++; // Increment the nested loop step
nestedLoopStartTime3 = currentTime; // Reset the nested loop timer
}
currentTime = millis(); // Update the current time
}
setPedestrianLights(255, 0);
loopStep++;
previousTime = currentTime;
}
break;
case 4: // Traffic Red, Pedestrian Red
if (currentTime - previousTime >= 5000) {
Serial.println("" + Status3);
setRgbColour(255, 0);
setPedestrianLights(255, 0);
loopStep++;
previousTime = currentTime;
}
break;
case 5: // Traffic Green, Pedestrian Red
if (currentTime - previousTime >= 5000) {
Serial.println("" + Status1);
setRgbColour(0, 255);
setPedestrianLights(255, 0);
loopStep++;
previousTime = currentTime;
}
break;
case 6: // End of sequence, Traffic Green Pedestrian Red
if (currentTime - previousTime >= 1000) {
Serial.println("" + Status1);
setRgbColour(0, 255);
setPedestrianLights(255, 0);
loopStep = 0;
loopComplete = true;
loopStarted = false; // Reset loop to start only when the button is pressed again
previousTime = currentTime;
resetLoop();
}
break;
}
}
// Check if the button was pressed during the loop
if (loopComplete) {
resetLoop();
}
// Check if it's time to update the status
}
void statusUpdate() {
// Print the current status to the serial monitor
switch (loopStep) {
case 0:
Serial.println("" + Status1);
break;
case 1:
Serial.println("" + Status2);
break;
case 2:
Serial.println("" + Status3);
break;
case 3:
Serial.println("" + Status4);
break;
case 4:
Serial.println("" + Status5);
break;
case 5:
Serial.println("" + Status3);
break;
case 6:
Serial.println("" + Status1);
break;
}
}
void resetLoop() {
loopStep = 0;
loopComplete = false;
}