Proyecto realizado por alumnado de 4º de ESO del IES La Laguna.
A continuación el código:
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(7, OUTPUT);
pinMode(4, OUTPUT);
pinMode(8, OUTPUT);
}// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a seconddigitalWrite(12, HIGH);digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(8, HIGH); digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(7500); // wait for a second
digitalWrite(8, LOW); digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second}
Tras comprobar que funcionaba se depuró el código haciendo uso de funciones la función for que de la siguiente forma:
for (int i=0; i<15; i++)
declara i y prueba si es menor que 15, incrementa i. –> Esto provoca el parpadeo del ámbar.
/*
Codigo de semáforo vehículo/peatones creado por Cristian Samuel Hernández Galván.
4 de ESO IES La Laguna
Curso 2015/16
*/// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.// semáforo de vehículos
pinMode(13, OUTPUT); // verde vehiculos
pinMode(12, OUTPUT); // ámbar vehículos
pinMode(8, OUTPUT); // rojo vehículo
// semáforo de peatones
pinMode(4, OUTPUT); // verde peatones
pinMode(7, OUTPUT); //rojo peatones
}// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH);
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW);
delay(100); // wait for 0,1 secondfor (int i=0; i<15; i++) // declara i y prueba si es { // menor que 15, incrementa i. –> Esto provoca el parpadeo del ámbar.
digitalWrite(12, HIGH);
delay(100); // wait for 0,1 second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for 0,1 second
}digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for 0,1 seconddigitalWrite(8, HIGH); digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(7500); // wait for a 7,5 second
digitalWrite(8, LOW); digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for 0,1 second
}