mpmcws

Ingresso tensione variabile / uscita relè

Jun 15th, 2018
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Bicicletta
  2. //aprile 2018 by Marco Cerani
  3. //code open source
  4. int A = 7;
  5. int B = 8;
  6. int C = 9;
  7. int D = 10;
  8. int E = 11;
  9. int F = 12;
  10. unsigned long time;
  11. void setup()
  12. {
  13.   Serial.begin(9600);
  14.   pinMode(A, OUTPUT);
  15.   pinMode(B, OUTPUT);
  16.   pinMode(C, OUTPUT);
  17.   pinMode(D, OUTPUT);
  18.   pinMode(E, OUTPUT);
  19.   pinMode(F, OUTPUT);
  20.   Serial.println (" CIAO MARCO, IO SONO PRONTO");
  21.   delay(3000);
  22. }
  23. void loop()
  24. {
  25.   time = millis();
  26.   int TD;
  27.   float volt;
  28.   TD = analogRead(0);
  29.   volt = TD / 1024.0 * 5.0;
  30.   Serial.print (volt);
  31.   Serial.println (" Volt");
  32.   digitalWrite(A, HIGH);
  33.   digitalWrite(B, HIGH);
  34.   digitalWrite(C, HIGH);
  35.   digitalWrite(D, HIGH);
  36.  
  37.   if (volt > 3.8)
  38.   {
  39.     digitalWrite(A, LOW);
  40.   }
  41.  
  42.   if (volt > 3.85)
  43.   {
  44.     digitalWrite(B, LOW);
  45.   }
  46.  
  47.   if (volt > 3.90)
  48.   {
  49.     digitalWrite(C, LOW);
  50.   }
  51.  
  52.   if (volt > 3.95)
  53.   { digitalWrite(D, LOW);
  54.     Serial.print(time);
  55.     Serial.println (" Time ");
  56.   }
  57.  
  58.   if (volt < 3.95)
  59.   {
  60.     digitalWrite(D, HIGH);
  61.  }
  62.   Serial.println ( );
  63.   delay(500);
  64. }
RAW Paste Data