semaforo

From maria chiara rosania, 10 Months ago, written in C++, viewed 137 times.
URL https://paste.monocul.us/view/c9160645 Embed
Download Paste or View Raw
  1.  
  2. int verde = 2;
  3. int giallo = 4;
  4. int rosso = 6;
  5.  
  6. int verdeP = 8;
  7. int gialloP = 10;
  8. int rossoP = 12;
  9.  
  10. int pulsante = 9;
  11.  
  12. // Variables will change:
  13. int verdeState = LOW;            
  14. int gialloState = LOW;
  15. int rossoState = LOW;
  16. int verdePState = LOW;
  17. int gialloPState = LOW;
  18. int rossoPState = LOW;
  19.  
  20.  
  21. unsigned long previousMillis = 0;        
  22.  
  23. // constants won't change:
  24. const long int1 = 9000;          
  25. const long int2 = 3000;
  26. const long int3 = 4500;
  27. const long int4 = 3000;
  28.  
  29. void setup()
  30. {
  31.  
  32.   pinMode (rosso, OUTPUT);
  33.   pinMode (giallo, OUTPUT);
  34.   pinMode (verde, OUTPUT);
  35.   pinMode (rossoP, OUTPUT);
  36.   pinMode (gialloP, OUTPUT);
  37.   pinMode (verdeP, OUTPUT);
  38.  
  39.   Serial.begin(9600);
  40. }
  41.  
  42. void loop() {
  43.  
  44.   unsigned long currentMillis = millis();
  45.  
  46.       // verde macchine e rosso dei pedoni
  47. if (currentMillis - previousMillis >= int1) {
  48.    
  49.     previousMillis = currentMillis;
  50.  
  51.    
  52.     if (verde == LOW && rossoP == LOW)
  53.     {
  54.       verde = HIGH;
  55.       rossoP = HIGH;
  56.     }
  57.  
  58.     // set the LED with the ledState of the variable:
  59.     digitalWrite(verde, HIGH);
  60.     digitalWrite (rossoP, HIGH);
  61.   }
  62.  
  63.       // giallo macchine e ancora rosso dei pedoni
  64. if (currentMillis - previousMillis >= int2) {
  65.    
  66.    
  67.     previousMillis = currentMillis;
  68.  
  69.    
  70.     if (giallo == LOW && rossoP == LOW)
  71.     {
  72.       giallo = HIGH;
  73.       rossoP = HIGH;
  74.     }
  75.  
  76.     // set the LED with the ledState of the variable:
  77.     digitalWrite(giallo, HIGH);
  78.     digitalWrite (rossoP, HIGH);
  79.   }
  80.  
  81.     // rosso macchine e verde dei pedoni
  82. if (currentMillis - previousMillis >= int3) {
  83.    
  84.     previousMillis = currentMillis;
  85.  
  86.    
  87.     if (rosso == LOW && verdeP == LOW)
  88.     {
  89.       rosso = HIGH;
  90.       verdeP = HIGH;
  91.     }
  92.  
  93.     // set the LED with the ledState of the variable:
  94.     digitalWrite(rosso, HIGH);
  95.     digitalWrite (verdeP, HIGH);
  96.   }
  97.  
  98.     // ancora rosso macchine e giallo dei pedoni
  99. if (currentMillis - previousMillis >= int4) {
  100.    
  101.     previousMillis = currentMillis;
  102.  
  103.    
  104.     if (rosso == LOW && gialloP == LOW)
  105.     {
  106.       rosso = HIGH;
  107.       gialloP = HIGH;
  108.     }
  109.  
  110.     // set the LED with the ledState of the variable:
  111.     digitalWrite(rosso, HIGH);
  112.     digitalWrite (gialloP, HIGH);
  113.   }
  114.  
  115. }

Reply to "semaforo"

Here you can reply to the paste above