Sketch Semaforo con Arduino

int rosso1 = 2;    //Definisco i pin, dal 2 al 13 tutte uscite
int giallo1 = 3;
int verde1 = 4;
int rosso2 = 5;
int giallo2 = 6;
int verde2 = 7;
int rp1 = 8;
int gp1 = 9;
int vp1 = 10;
int rp2 = 11;
int gp2 = 12;
int vp2 = 13;




void setup ()
{
  


  pinMode(rosso1, OUTPUT);  
  pinMode(giallo1, OUTPUT);  
  pinMode(verde1, OUTPUT);  
  pinMode(rosso2, OUTPUT);  
  pinMode(giallo2, OUTPUT);  
  pinMode(verde2, OUTPUT);  
  pinMode(vp1, OUTPUT);  
  pinMode(rp1, OUTPUT);  
  pinMode(vp2, OUTPUT);  
  pinMode(rp2, OUTPUT);  
  pinMode(gp1, OUTPUT);  
  pinMode(gp2, OUTPUT);

  
// Da qui il codice semaforo funzionante: Accendo e spengo in sequenza i led, per verificare che tutte le uscite siano collegate e funzionanti//

  digitalWrite (rosso1, HIGH);
  delay (100);
  digitalWrite (giallo1, HIGH);
  delay (100);
  digitalWrite (verde1, HIGH);
  delay (500);
  digitalWrite (rosso2, HIGH);
  delay (100);
  digitalWrite (giallo2, HIGH);
  delay (100);
  digitalWrite (verde2, HIGH);
  delay (500);
  digitalWrite (rosso1, LOW);
  delay (100);
  digitalWrite (giallo1, LOW);
  delay (100);
  digitalWrite (verde1, LOW);
  delay (500);
  digitalWrite (rosso2, LOW);
  delay (100);
  digitalWrite (giallo2, LOW);
  delay (100);
  digitalWrite (verde2, LOW);
  delay (500);
  digitalWrite (rp1, HIGH);
  delay (100);
  digitalWrite (gp1, HIGH);
  delay (100);
  digitalWrite (vp1, HIGH);
  delay (100);
  digitalWrite (rp2, HIGH);
  delay (100);
  digitalWrite (gp2, HIGH);
  delay (100);
  digitalWrite (vp2, HIGH);
  delay (500);
  digitalWrite (rp1, LOW);
  delay (100);
  digitalWrite (gp1, LOW);
  delay (100);
  digitalWrite (vp1, LOW);
  delay (100);
  digitalWrite (rp2, LOW);
  delay (100);
  digitalWrite (gp2, LOW);
  delay (100);
  digitalWrite (vp2, LOW);
  delay (500);

  digitalWrite(rosso1, HIGH);
  digitalWrite(rosso2, HIGH);
  digitalWrite(rp1, HIGH);
  digitalWrite(rp2, HIGH);
  delay(2000);

}



void loop ()

{

//questa parte è il codice di funzionamento normale del semaforo//
 
  digitalWrite (rosso1, HIGH);
  digitalWrite (rp1, HIGH);
  digitalWrite (verde2, LOW);
  digitalWrite (vp2, LOW);
  delay (3000);
  digitalWrite(giallo1, HIGH);
  digitalWrite(giallo2, HIGH);
  digitalWrite(gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(400);
  digitalWrite(gp1, LOW);
  digitalWrite(gp2, LOW);
  delay(400);
  digitalWrite(gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(400);
  digitalWrite(gp1, LOW);
  digitalWrite(gp2, LOW);
  delay(400);
  digitalWrite(gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(2000);
  digitalWrite(rosso1, HIGH);
  digitalWrite(verde1, LOW);
  digitalWrite (verde2, HIGH);
  digitalWrite (rosso2, LOW);
  digitalWrite (vp2, HIGH);
  digitalWrite (rp2, LOW);
  digitalWrite(rp1, HIGH);
  digitalWrite(vp1, LOW);
  digitalWrite(giallo1, LOW);
  digitalWrite(gp1, LOW);
  digitalWrite(giallo2, LOW);
  digitalWrite(gp2, LOW);
  delay (3000);
  digitalWrite(giallo1, HIGH);
  digitalWrite (giallo2, HIGH);
  digitalWrite (gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(400);
  digitalWrite(gp2, LOW);
  digitalWrite(gp1, LOW);
  delay(400);
  digitalWrite(gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(400);
  digitalWrite(gp2, LOW);
  digitalWrite(gp1, LOW);
  delay(400);
  digitalWrite(gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(2000);
  digitalWrite (rosso1, HIGH);
  digitalWrite(rp1, HIGH);
  digitalWrite(giallo2, LOW);
  digitalWrite(gp2, LOW);
  digitalWrite(giallo1, LOW);
  digitalWrite(gp1, LOW);
  digitalWrite(verde2, LOW);
  digitalWrite(vp2, LOW);
  digitalWrite(rosso2, HIGH);
  digitalWrite(rp2, HIGH);
  digitalWrite(verde1, LOW);
  digitalWrite(vp1, LOW);
  delay (2500);
  digitalWrite (rosso1, LOW);
  digitalWrite (verde1, HIGH);
  digitalWrite (rosso2, HIGH);
  digitalWrite(verde2, LOW);
  digitalWrite(rp1, LOW);
  digitalWrite(rp2, HIGH);
  digitalWrite(vp1, HIGH);
  digitalWrite(vp2, LOW);
  delay (5000);
  digitalWrite(giallo1, HIGH);
  digitalWrite (giallo2, HIGH);
  digitalWrite (gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(400);
  digitalWrite(gp2, LOW);
  digitalWrite(gp1, LOW);
  delay(400);
  digitalWrite(gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay(400);
  digitalWrite(gp2, LOW);
  digitalWrite(gp1, LOW);
  delay(400);
  digitalWrite(gp2, HIGH);
  digitalWrite(gp1, HIGH);
  delay (2500);
  digitalWrite (verde1, LOW);
  digitalWrite (giallo1, LOW);
  digitalWrite(giallo2, LOW);
  digitalWrite(gp1, LOW);
  digitalWrite(gp2, LOW);
  digitalWrite(vp1, LOW);
  digitalWrite(rosso1, HIGH);
  digitalWrite(rp1, HIGH);
  digitalWrite(verde2, HIGH);
  digitalWrite(vp2, HIGH);


}
Annunci

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...