Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.40 KB | None | 0 0
  1. //#include <LiquidCrystal.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <OneWire.h>
  4. #include <DallasTemperature.h> // biblioteka do obsługi wyświetlacza na I2C
  5. #include <Wire.h>
  6. #include <DS3231.h> // biblioteka do obsługi zegara ds3231
  7. //LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
  8. LiquidCrystal_I2C lcd(0x27,16,2);
  9. #define ONE_WIRE_BUS 13
  10. OneWire oneWire(ONE_WIRE_BUS);
  11. DallasTemperature sensors(&oneWire);
  12. DS3231 clock;
  13. RTCDateTime dt;
  14. int jo=0; //zmienna pierwszej cyfry
  15. int oj=0; //zmienna drugiej cyfry
  16. int io=0; //zmienna trzeciej cyfry
  17. int oi=0; //zmienna czwartej cyfry
  18.  
  19. int ioo=0;  //zmienna pierwszej cyfry dnia roku
  20. int oio=0;  //zmienna drugiej cyfry dnia roku
  21. int ooi=0;  //zmienna trzeciej cyfry dnia roku
  22.  
  23. long startowa = 0;    
  24. long ileczasu = 7000;          
  25. int tryb = 0;        
  26.  
  27.  
  28. // kody poszczególnych dużych znaków
  29.  
  30.  
  31. byte LT[8] =
  32. {
  33.   B00111,
  34.   B01111,
  35.   B11111,
  36.   B11111,
  37.   B11111,
  38.   B11111,
  39.   B11111,
  40.   B11111
  41. };
  42. byte UB[8] =
  43. {
  44.   B11111,
  45.   B11111,
  46.   B11111,
  47.   B00000,
  48.   B00000,
  49.   B00000,
  50.   B00000,
  51.   B00000
  52. };
  53. byte RT[8] =
  54. {
  55.   B11100,
  56.   B11110,
  57.   B11111,
  58.   B11111,
  59.   B11111,
  60.   B11111,
  61.   B11111,
  62.   B11111
  63. };
  64. byte LL[8] =
  65. {
  66.   B11111,
  67.   B11111,
  68.   B11111,
  69.   B11111,
  70.   B11111,
  71.   B11111,
  72.   B01111,
  73.   B00111
  74. };
  75. byte LB[8] =
  76. {
  77.   B00000,
  78.   B00000,
  79.   B00000,
  80.   B00000,
  81.   B00000,
  82.   B11111,
  83.   B11111,
  84.   B11111
  85. };
  86. byte LR[8] =
  87. {
  88.   B11111,
  89.   B11111,
  90.   B11111,
  91.   B11111,
  92.   B11111,
  93.   B11111,
  94.   B11110,
  95.   B11100
  96. };
  97. byte UMB[8] =
  98. {
  99.   B11111,
  100.   B11111,
  101.   B11111,
  102.   B00000,
  103.   B00000,
  104.   B00000,
  105.   B11111,
  106.   B11111
  107. };
  108.  
  109.  
  110. byte LMB[8] =
  111. {
  112.   B11111,
  113.   B00000,
  114.   B00000,
  115.   B00000,
  116.   B00000,
  117.   B11111,
  118.   B11111,
  119.   B11111
  120. };
  121.  
  122.  
  123. void setup()
  124. {
  125.  // lcd.begin(16,2); // inicjalizujemy pracę wyświetlacza
  126.  // clock.begin();
  127.  lcd.begin(); // inicjalizujemy pracę wyświetlacza
  128.   lcd.backlight(); // inicjalizujemy zegar
  129.    sensors.begin();
  130.   lcd.createChar(1,UB);
  131.   lcd.createChar(2,RT);
  132.   lcd.createChar(3,LL);
  133.   lcd.createChar(4,LB);
  134.   lcd.createChar(5,LR);
  135.   lcd.createChar(6,UMB);
  136.   lcd.createChar(7,LMB);
  137.   lcd.createChar(8,LT);
  138.   //clock.setDateTime(__DATE__, __TIME__);
  139.  
  140. }
  141.  
  142. void custom(int col)
  143. {
  144.   lcd.setCursor(col, 0);
  145.   lcd.write(8);  
  146.   lcd.write(1);
  147.   lcd.write(2);
  148.   lcd.setCursor(col, 1);
  149.   lcd.write(3);  
  150.   lcd.write(4);  
  151.   lcd.write(5);
  152. }
  153.  
  154. void custom1(int col)
  155. {
  156.   lcd.setCursor(col,0);
  157.   lcd.write(1);
  158.   lcd.write(2);
  159.   lcd.setCursor(col,1);
  160.   lcd.write(4);
  161.   lcd.write(255);
  162.   lcd.write(4);
  163. }
  164.  
  165. void custom2(int col)
  166. {
  167.   lcd.setCursor(col,0);
  168.   lcd.write(6);
  169.   lcd.write(6);
  170.   lcd.write(2);
  171.   lcd.setCursor(col, 1);
  172.   lcd.write(3);
  173.   lcd.write(7);
  174.   lcd.write(7);
  175. }
  176.  
  177. void custom3(int col)
  178. {
  179.   lcd.setCursor(col,0);
  180.   lcd.write(6);
  181.   lcd.write(6);
  182.   lcd.write(2);
  183.   lcd.setCursor(col, 1);
  184.   lcd.write(7);
  185.   lcd.write(7);
  186.   lcd.write(5);
  187. }
  188.  
  189. void custom4(int col)
  190. {
  191.   lcd.setCursor(col,0);
  192.   lcd.write(3);
  193.   lcd.write(4);
  194.   lcd.write(2);
  195.   lcd.setCursor(col+2, 1);
  196.   lcd.write(255);
  197. }
  198.  
  199. void custom5(int col)
  200. {
  201.   lcd.setCursor(col,0);
  202.   lcd.write(255);
  203.   lcd.write(6);
  204.   lcd.write(6);
  205.   lcd.setCursor(col, 1);
  206.   lcd.write(7);
  207.   lcd.write(7);
  208.   lcd.write(5);
  209. }
  210.  
  211. void custom6(int col)
  212. {
  213.   lcd.setCursor(col,0);
  214.   lcd.write(8);
  215.   lcd.write(6);
  216.   lcd.write(6);
  217.   lcd.setCursor(col, 1);
  218.   lcd.write(3);
  219.   lcd.write(7);
  220.   lcd.write(5);
  221. }
  222.  
  223. void custom7(int col)
  224. {
  225.   lcd.setCursor(col,0);
  226.   lcd.write(1);
  227.   lcd.write(1);
  228.   lcd.write(2);
  229.   lcd.setCursor(col+1, 1);
  230.   lcd.write(8);
  231. }
  232.  
  233. void custom8(int col)
  234. {
  235.   lcd.setCursor(col,0);
  236.   lcd.write(8);
  237.   lcd.write(6);
  238.   lcd.write(2);
  239.   lcd.setCursor(col, 1);
  240.   lcd.write(3);
  241.   lcd.write(7);
  242.   lcd.write(5);
  243. }
  244.  
  245. void custom9(int col)
  246. {
  247.   lcd.setCursor(col,0);
  248.   lcd.write(8);
  249.   lcd.write(6);
  250.   lcd.write(2);
  251.   lcd.setCursor(col+2, 1);
  252.   lcd.write(255);
  253. }
  254.  
  255. void customC(int col)
  256. {
  257.   lcd.setCursor(col,0);
  258.   lcd.write(8);
  259.   lcd.write(1);
  260.   lcd.write(1);
  261.   lcd.setCursor(col,1);
  262.   lcd.write(3);
  263.   lcd.write(4);
  264.   lcd.write(4);
  265. }
  266.  
  267. void custom30(int col)
  268. {
  269.   lcd.setCursor(col,0);
  270.   lcd.write(165);
  271.   lcd.setCursor(col, 1);
  272.   lcd.write(165);
  273. }
  274.  
  275. void custom29(int col)
  276. {
  277.   lcd.setCursor(col,0);
  278.   lcd.write(223); }
  279.  
  280.  
  281. void printNumber(int value, int col) {
  282.   if (value == 0) {
  283.     custom(col);
  284.   } if (value == 1) {
  285.     custom1(col);
  286.   } if (value == 2) {
  287.     custom2(col);
  288.   } if (value == 3) {
  289.     custom3(col);
  290.   } if (value == 4) {
  291.     custom4(col);
  292.   } if (value == 5) {
  293.     custom5(col);
  294.   } if (value == 6) {
  295.     custom6(col);
  296.   } if (value == 7) {
  297.     custom7(col);
  298.   } if (value == 8) {
  299.     custom8(col);
  300.   } if (value == 9) {
  301.     custom9(col);
  302.   } if (value == 30) {
  303.     custom30(col);
  304.   } if (value == 35) {
  305.     customC(col);
  306.   } if (value == 29) {
  307.     custom29(col);
  308.   }
  309. }
  310.  
  311.  
  312.  
  313. void loop()
  314. {
  315.   unsigned long czas = millis();  // ustala zmienną czas w milisekundach
  316.  
  317.   if(czas - startowa > ileczasu) { // jeśli czas jaki upłynął od włączenia arduino jest większy niż zadeklarowaliśmy w "ileczasu"
  318.     lcd.clear(); // czyści ekran przed każdą zmianą napisu żeby nic się nie nakładało
  319.     startowa = czas;  // zrównuje start z czasem który się nalicza w milisekundach
  320.     tryb = tryb+1; // przełącza ekran na następny
  321.   }
  322.  
  323.  dt = clock.getDateTime(); // pobiera czas z zegara
  324.   sensors.requestTemperatures();
  325.  
  326. if(tryb==0) {
  327.   pokaczas(); // funkcja wyświetlająca czas
  328.  }
  329.  
  330.  if(tryb==1) {
  331.   pokaztemperature(); // funkcja wyświetlająca dzień roku
  332.   }
  333.  
  334.   if(tryb==2){ // powraca do pierwszego ekranu
  335.   tryb=0;
  336.   }
  337. }
  338. void pokaczas(){
  339.   String czas=(clock.dateFormat("H:i:a", dt)); // tworzymy stringa z odczytu godziny:minuty:sekundy z zegara i zapisujemy do stringa "czas"
  340.  
  341.   jo=czas[0]-48;
  342.   oj=czas[1]-48;
  343.   io=czas[3]-48;
  344.   oi=czas[4]-48;
  345.  
  346.   printNumber(jo, 0); // wyświetlamy po kolei każdą liczbę godziny i minuty
  347.   printNumber(oj, 4);
  348.   printNumber(30, 7); // wyświetlamy dwukropek
  349.   printNumber(io, 9);
  350.   printNumber(oi, 13);
  351. //  lcd.setCursor(14,1);
  352. //  lcd.print(clock.dateFormat("s", dt)); // wyświetlamy sekundy
  353. }
  354. void pokaztemperature(){
  355.  
  356. String temperatura = String(sensors.getTempCByIndex(0));
  357.  
  358.   ioo=temperatura[0]-48;
  359.   oio=temperatura[1]-48;
  360.  // ooi=temperatura[2]-48;
  361.  
  362.   printNumber(ioo, 0);
  363.   printNumber(oio, 4);
  364.   printNumber(29,7);
  365.   printNumber(35, 8);
  366.  
  367. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement