For our final project, we were required to create something that was interactive and used serial communication with either a computer or another Arduino!
So we decided to use the servo motors to make cars that could be controlled with a throttle, utilizing a potentiometer for stop and go. All of that would work off of one Arduino, mean while we created a topiary/stop-light-like
Schematics and more coming soon… Once it is emailed to me!
Well I intended for there to be a video…but, apparently I did not record the video right!
Here is the code for the portion that I worked on… The topiary street light!
boolean isStop;
unsigned int time;
unsigned int lastTimeRed;
unsigned int lastTimeLEDOn;
int lastLEDOn;
int pinArray[] = {0, 2, 3, 4};
int timeRand = 1000;
int timeRandRed = 1000;
void setup() {
isStop = false;
time = millis();
lastTimeRed = time;
lastLEDOn = 1;
lightLED(1);
for(int a = 1; a timeRand) {
isStop = true;
lightLED(2);
}
} else {
if((time-lastTimeLEDOn) > 1000) {
if(lastLEDOn == 2) {
Serial.print(1, DEC);
// Serial.print(“ONE “);
lightLED(3);
lastTimeRed = time;
//Serial.println(“red”);
} else if(lastLEDOn == 3 && (time-lastTimeLEDOn) > timeRandRed) {
lightLED(1);
Serial.print(2, DEC);
isStop = false;
lastTimeRed = time;
randomSeed(time);
timeRand = random(5000, 10000);
timeRandRed = random(3000, 7000);
//Serial.println(“GREEN!!”);
}
}
}
}
void lightLED(int color) {
int prevLED = color-1;
if(prevLED < 1) {
prevLED = 3;
}
lastLEDOn = color;
lastTimeLEDOn = millis();
digitalWrite(pinArray[color], HIGH);
digitalWrite(pinArray[prevLED], LOW);
//Serial.print(color, DEC);
//Serial.print(" prev ");
//Serial.println(prevLED, DEC);
}



















