Components and supplies
5 mm LED: Red
Push Button
Resistor 2.21k ohm
Arduino UNO
Breadboard (generic)
5 mm LED: Yellow
Resistor 10k ohm
5 mm LED: Green
Apps and platforms
Arduino IDE
Project description
Code
Schoolwork.ino
c_cpp
This is... just the whole thing. This is all the code.
1int ledPin = 14; //set the LED pin to 14 (used for the loop) 2int loopTimes = 6; //set the first loop to go 6 times 3int butState = 0; //Button State Variable 4 // 5void setup(){ // 6 while (loopTimes > 0){ //Repeat until loopTimes is 0, in this case 6 times 7 ledPin -= 1; //go to the next LED pin (why I started at 14) 8 pinMode(ledPin, OUTPUT); //set the LED pin to an output 9 digitalWrite(ledPin, LOW); //make sure it's off (can never be too safe) 10 loopTimes -= 1;} //go to the next iteration of the loop 11 loopTimes = 2; //set the next loop to go twice 12 pinMode(7, INPUT); //set the Button as an input 13} // 14 // 15void loop(){ // 16 ledPin = 9; //select the pedestrian red light 17 digitalWrite(ledPin, HIGH); //turn the LED on 18 ledPin = 13; //select the car green light 19 digitalWrite(ledPin, HIGH); //turn the LED on 20 butState = digitalRead(7); //get the state of the button 21 if (butState==1){ //if the button is pressed, begin the sequence 22 delay (6000); //wait 6 seconds 23 while (loopTimes > 0){ //Repeat until loopTimes is 0, in this case twice 24 delay(2000); //wait 2 seconds 25 digitalWrite(ledPin, LOW); //turn the LED (starting w/ car green light) off 26 ledPin -= 1; //move to the next LED 27 digitalWrite(ledPin, HIGH); //turn the LED on 28 loopTimes -= 1;} //go to the next iteration of the loop 29 loopTimes = 5; //set the next loop to go 5 times 30 ledPin = 9; //select the Pedestrian Red Light 31 digitalWrite(ledPin, LOW); //turn the LED off 32 ledPin = 8; //select the Pedestrian Green Light 33 digitalWrite(ledPin, HIGH); //turn the LED on 34 delay(4000); //wait 4 second 35 digitalWrite(ledPin, LOW); //turn the LED off 36 ledPin = 9; //select the Pedestrian Red Light 37 digitalWrite(ledPin, HIGH); //turn the LED on 38 while (loopTimes > 0){ //Repeat until loopTimes is 0, in this case 5 times 39 delay(200); //wait 0.2 seconds 40 digitalWrite(ledPin, LOW); //turn the LED off 41 delay(200); //wait 0.2 seconds 42 digitalWrite(ledPin, HIGH); //turn the LED on 43 loopTimes -= 1;} //go to the next iteration of the loop 44 loopTimes = 2; //set the next loop to go twice 45 ledPin = 11; //select the Car Red Light 46 digitalWrite(ledPin, LOW);} //set the LED to off 47} // 48
Schoolwork.ino
c_cpp
This is... just the whole thing. This is all the code.
1int ledPin = 14; //set the LED pin to 14 (used for the loop) 2int loopTimes = 6; //set the first loop to go 6 times 3int butState = 0; //Button State Variable 4 // 5void setup(){ // 6 while (loopTimes > 0){ //Repeat until loopTimes is 0, in this case 6 times 7 ledPin -= 1; //go to the next LED pin (why I started at 14) 8 pinMode(ledPin, OUTPUT); //set the LED pin to an output 9 digitalWrite(ledPin, LOW); //make sure it's off (can never be too safe) 10 loopTimes -= 1;} //go to the next iteration of the loop 11 loopTimes = 2; //set the next loop to go twice 12 pinMode(7, INPUT); //set the Button as an input 13} // 14 // 15void loop(){ // 16 ledPin = 9; //select the pedestrian red light 17 digitalWrite(ledPin, HIGH); //turn the LED on 18 ledPin = 13; //select the car green light 19 digitalWrite(ledPin, HIGH); //turn the LED on 20 butState = digitalRead(7); //get the state of the button 21 if (butState==1){ //if the button is pressed, begin the sequence 22 delay (6000); //wait 6 seconds 23 while (loopTimes > 0){ //Repeat until loopTimes is 0, in this case twice 24 delay(2000); //wait 2 seconds 25 digitalWrite(ledPin, LOW); //turn the LED (starting w/ car green light) off 26 ledPin -= 1; //move to the next LED 27 digitalWrite(ledPin, HIGH); //turn the LED on 28 loopTimes -= 1;} //go to the next iteration of the loop 29 loopTimes = 5; //set the next loop to go 5 times 30 ledPin = 9; //select the Pedestrian Red Light 31 digitalWrite(ledPin, LOW); //turn the LED off 32 ledPin = 8; //select the Pedestrian Green Light 33 digitalWrite(ledPin, HIGH); //turn the LED on 34 delay(4000); //wait 4 second 35 digitalWrite(ledPin, LOW); //turn the LED off 36 ledPin = 9; //select the Pedestrian Red Light 37 digitalWrite(ledPin, HIGH); //turn the LED on 38 while (loopTimes > 0){ //Repeat until loopTimes is 0, in this case 5 times 39 delay(200); //wait 0.2 seconds 40 digitalWrite(ledPin, LOW); //turn the LED off 41 delay(200); //wait 0.2 seconds 42 digitalWrite(ledPin, HIGH); //turn the LED on 43 loopTimes -= 1;} //go to the next iteration of the loop 44 loopTimes = 2; //set the next loop to go twice 45 ledPin = 11; //select the Car Red Light 46 digitalWrite(ledPin, LOW);} //set the LED to off 47} // 48
Downloadable files
Circuit
A picture of my circuit, and the link to it
Circuit
Comments
Only logged in users can leave comments
drhm
2 years ago
thanks
ShreyanR
4 years ago
great job it came out nice
drhm
4 years ago
Wow amazing job that looks really cool
drhm
2 years ago
thanks
drhm
2 years ago
Wow amazing job that looks really cool