ElectroFactory

Untitled

Mar 9th, 2021 (edited)
511
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <Wire.h>
  4. #include <LiquidCrystal_I2C.h>
  5.  
  6. #define One_WIRE_BUS 6
  7. OneWire oneWire(One_WIRE_BUS);
  8. DallasTemperature sensors(&oneWire);
  9. LiquidCrystal_I2C lcd(0x27, 20, 4);
  10.  
  11. #define Relay 11
  12. #define BtnMinor 2
  13. #define BtnMajor 3
  14. int DELAI_MESURE_TEMPERATURE = 5;
  15. int TIME_BOUTTON = 500;
  16.  
  17. int TmpConsign = 0;
  18. int EtaBtnMinor = 0;
  19. int EtaBtnMajor = 0;
  20. int DebugTmp = 10;
  21.  
  22. void setup(void) {
  23.   lcd.init();
  24.   lcd.backlight();
  25.  
  26.   lcd.setCursor(0, 0);
  27.   lcd.print("C1");
  28.   lcd.setCursor(3, 0);
  29.   lcd.print(float(TmpConsign));
  30.  
  31.   Serial.begin(9600);
  32.  
  33.   pinMode(BtnMinor, INPUT);
  34.   pinMode(BtnMajor, INPUT);
  35.   pinMode(Relay, OUTPUT);
  36. }
  37.  
  38. void loop() {
  39.  
  40.   static uint32_t derniereMesure = millis();
  41.   static uint32_t timer_transition = millis();
  42.   static float temperature = 0;
  43.  
  44.   EtaBtnMinor = digitalRead(BtnMinor);
  45.   EtaBtnMajor = digitalRead(BtnMajor);
  46.  
  47.   if ((millis() - derniereMesure) >= DELAI_MESURE_TEMPERATURE) {
  48.     sensors.requestTemperatures();
  49.     temperature = sensors.getTempCByIndex(0);
  50.     derniereMesure = millis();
  51.   }
  52.  
  53.   lcd.setCursor(0, 1);
  54.   lcd.print("T1");
  55.  
  56.   lcd.setCursor(3, 1);
  57.   //lcd.print(TmpConsign); //debug lcd temp
  58.   lcd.print(temperature);
  59.  
  60.   if (EtaBtnMinor == LOW) {
  61.     if ((millis() - timer_transition) > TIME_BOUTTON) {
  62.       TmpConsign++;
  63.       lcd.setCursor(0, 0);
  64.       lcd.print("C1");
  65.       lcd.setCursor(3, 0);
  66.       lcd.print(float(TmpConsign));
  67.       Serial.println(TmpConsign);
  68.       timer_transition += TIME_BOUTTON;
  69.     }
  70.   }
  71.  
  72.   else if (EtaBtnMajor == LOW) {
  73.     if ((millis() - timer_transition) > TIME_BOUTTON) {
  74.       TmpConsign--; //s'execute donc tout les 1/2s quand tu laisse appuyé
  75.       lcd.setCursor(0, 0);
  76.       lcd.print("C1");
  77.       lcd.setCursor(3, 0);
  78.       lcd.print(float(TmpConsign));
  79.       Serial.println(TmpConsign);
  80.       timer_transition += TIME_BOUTTON; //on rajout la valeur de notre temps à la variable pour le prochain cycle
  81.     }
  82.   }
  83.  
  84.   else if (temperature >= TmpConsign) {
  85.     digitalWrite(Relay, HIGH);
  86.   }
  87.  
  88.   else if (temperature < TmpConsign) {
  89.     digitalWrite(Relay, LOW);
  90.   }
  91. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×