Advertisement
granteeric

modif code vincenzo

Apr 17th, 2022
1,409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //char c;
  2.  
  3. const int sensorPin = A0;
  4.  
  5. //les 2 sont valables
  6. const int PIN_LED_MIN = 3;
  7. #define PIN_LED_MAX     4
  8.  
  9. float sensorValue;
  10. float voltageOut;
  11. float tempC;
  12. float tempK;
  13. float tempMin = 0.0 ;
  14. float tempMax = 50.0 ;
  15.  
  16. void setup() {
  17. // LM335
  18.   //pinMode(sensorPin, INPUT);  //pas nécessaire
  19.   Serial.begin(57600);
  20. //Led 3 e 4
  21.   pinMode(PIN_LED_MIN,OUTPUT);
  22.   pinMode(PIN_LED_MAX,OUTPUT);
  23.  
  24.   //par default il sont deja a LOW
  25.   digitalWrite(PIN_LED_MIN,LOW);
  26.   digitalWrite(PIN_LED_MAX,LOW);
  27. }
  28.  
  29.  
  30. void loop() {
  31.   sensorValue = analogRead(sensorPin);
  32.   voltageOut = (sensorValue * 5000) / 1023;   //pas 1024 10 bits de 0 à 1023 et pas de 1 à 1024
  33.   tempK = voltageOut / 10;
  34.   tempC = tempK - 273.15;
  35.   Serial.println(tempC);
  36. // LED 3 e 4
  37. if(tempC < tempMin){
  38.   digitalWrite(PIN_LED_MIN,HIGH);
  39. }
  40. else{digitalWrite(PIN_LED_MIN,LOW);
  41. }
  42.  
  43. //une autre facon de l'ecrire
  44. (tempC > tempMax) ? digitalWrite(PIN_LED_MAX,HIGH) :  digitalWrite(PIN_LED_MAX,LOW);
  45.  
  46. //tu peux mettre aussi une pause
  47. delay(2000);
  48. /*
  49. // ?? pouquoi une lecture sur le port Serie
  50. if (Serial.available()) {
  51.     c = Serial.read();
  52.     if (c == 'C') {digitalWrite(3,1);
  53.     delay (1);
  54.     }else {digitalWrite(3,0);
  55.     }
  56.     if (c == 'A') {digitalWrite(4,1);
  57.     delay (1);
  58.     }else {digitalWrite(4,0);
  59.     }
  60.     }
  61. */
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement