PowerTGS440

Untitled

Mar 22nd, 2024
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | Software | 0 0
  1. #include <EEPROM.h>
  2. #include "GravityTDS.h"
  3. #include <OneWire.h>
  4. #include <DallasTemperature.h>
  5. #include <ThreeWire.h>
  6. #include <RtcDS1302.h>
  7. #include <SPI.h>
  8. #include <Wire.h>
  9. #include <Adafruit_GFX.h>
  10. #include <Adafruit_SH1106.h>
  11.  
  12.  
  13.  
  14. #define OLED_SDA 21
  15. #define OLED_SCL 22
  16. #define SCREEN_WIDTH 128
  17. #define SCREEN_HEIGHT 64
  18. #define ONE_WIRE_BUS 5
  19. Adafruit_SH1106 display(21, 22);
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. OneWire oneWire(ONE_WIRE_BUS);
  27.  
  28. DallasTemperature sensors(&oneWire);
  29.  
  30. ThreeWire myWire(19,18,23); //DAT,CLK,RST
  31. RtcDS1302<ThreeWire> Rtc(myWire);
  32.  
  33.  
  34. void Pompa1_wlacz()
  35. {
  36.    digitalWrite(33, HIGH);
  37.    // kod do wlaczenia pompy nr. 1
  38. }
  39.  
  40. void Pompa1_wylacz()
  41. {
  42.     digitalWrite(33, LOW);
  43.     // kod do wylaczenia pompy nr. 1
  44. }
  45.  
  46. void Pompa2_wlacz()
  47. {
  48.    digitalWrite(32, HIGH);
  49.    // kod do wlaczenia pompy nr. 1
  50. }
  51.  
  52. void Pompa2_wylacz()
  53. {
  54.     digitalWrite(32, LOW);
  55.     // kod do wylaczenia pompy nr. 1
  56. }
  57.  
  58. void pomiary()
  59. {
  60.     RtcDateTime now = Rtc.GetDateTime();
  61.     sensors.requestTemperatures();
  62.     static bool F_Pompa_1 = false;
  63.     static bool F_Pompa_2 = false;
  64.     int godzina = now.Hour();
  65.     int minuta = now.Minute();
  66.     int sekunda = now.Second();
  67.    
  68.  
  69.     // WLACZENIE POMPY nr. 1
  70.     if(godzina == 8 && minuta == 0 && sekunda == 0)
  71.     {
  72.       if(!F_Pompa_1)
  73.       {
  74.           Pompa1_wlacz();
  75.           F_Pompa_1 = true;
  76.       }
  77.     }
  78.  
  79.     // WYLACZENIE POMPY nr. 1  
  80.     if(godzina == 8 && minuta == 0 && sekunda == 5)
  81.     {
  82.         if(F_Pompa_1)
  83.         {
  84.             Pompa1_wylacz();
  85.             F_Pompa_1 = false;
  86.         }
  87.     }
  88.  
  89.     // WLACZENIE POMPY nr. 1
  90.     if(godzina == 19 && minuta == 0 && sekunda == 0)
  91.     {
  92.       if(!F_Pompa_1)
  93.       {
  94.           Pompa1_wlacz();
  95.           F_Pompa_1 = true;
  96.       }
  97.     }
  98.  
  99.     // WYLACZENIE POMPY nr. 1  
  100.     if(godzina == 19 && minuta ==15 && sekunda == 5)
  101.     {
  102.         if(F_Pompa_1)
  103.         {
  104.             Pompa1_wylacz();
  105.             F_Pompa_1 = false;
  106.         }
  107.     }
  108.  
  109.     // WLACZENIE POMPY nr. 2
  110.     if(godzina == 20 && minuta == 0 && sekunda == 0)
  111.     {
  112.       if(!F_Pompa_2)
  113.       {
  114.           Pompa2_wlacz();
  115.           F_Pompa_2 = true;
  116.       }
  117.     }
  118.  
  119.     // WYLACZENIE POMPY nr. 2  
  120.     if(godzina == 20 && minuta == 1 && sekunda == 5)
  121.     {
  122.         if(F_Pompa_2)
  123.         {
  124.             Pompa2_wylacz();
  125.             F_Pompa_2 = false;
  126.         }
  127.     }
  128.  
  129.    
  130. }
  131.  
  132.  
  133.  void setup()
  134. {
  135. pinMode(12,OUTPUT);
  136. pinMode(14,OUTPUT);
  137.  
  138.   Rtc.Begin();
  139.    RtcDateTime now = Rtc.GetDateTime();
  140.  
  141.  RtcDateTime currentTime = RtcDateTime(2024,03,21,8,14,45);
  142.  Rtc.SetDateTime(currentTime);
  143.   sensors.begin();
  144.   pinMode(33, OUTPUT);
  145.   pinMode(32, OUTPUT);
  146.   pinMode(25, OUTPUT);
  147.  
  148.     Serial.begin(115200);
  149.  
  150.  
  151. pinMode(13,INPUT);
  152.  
  153.    display.begin(SH1106_SWITCHCAPVCC, 0x3C);
  154.   delay(2000);
  155.   display.clearDisplay();
  156. }
  157.  
  158.  
  159.  
  160. void loop(void)
  161. {
  162. RtcDateTime now = Rtc.GetDateTime();
  163. digitalWrite(12,HIGH);
  164. digitalWrite(14,HIGH);
  165. pomiary();
  166.  
  167.     display.clearDisplay();
  168.  
  169.   display.setTextSize(1);
  170.   display.setTextColor(WHITE);
  171.   display.setCursor(0, 10);
  172.   // Display static text
  173.    display.print("TEMP: ");
  174.   display.println(sensors.getTempCByIndex(0));
  175.  
  176.   display.println(  );
  177.   display.print(now.Day() );
  178.   display.print("/");
  179.   display.print(now.Month());
  180.   display.print("/");
  181.   display.print(now.Year());
  182.   display.print("/");
  183.   display.print(now.Hour());
  184.   display.print("/");
  185.   display.print(now.Minute());
  186.   display.print("/");
  187.   display.print(now.Second());
  188.  
  189.   display.display();
  190.   display.clearDisplay();
  191.  ;
  192. }
  193.  
Advertisement
Add Comment
Please, Sign In to add comment