Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. // Data wire is plugged into pin 2 on the Arduino
  4. #define ONE_WIRE_BUS 2
  5. OneWire oneWire(ONE_WIRE_BUS);
  6. // Pass our oneWire reference to Dallas Temperature.
  7. DallasTemperature sensors(&oneWire);
  8.  
  9. #include "LedControl.h" //  need the library
  10. LedControl lc=LedControl(12,11,10,2); //
  11.  
  12. // pin 12 is connected to the MAX7219 pin 1
  13. // pin 11 is connected to the CLK pin 13
  14. // pin 10 is connected to LOAD pin 12
  15. // 1 as we are only using 1 MAX7219, 2 is 2xMAX...
  16.  
  17. int teplota = 30;
  18. byte a;
  19. byte segment1;
  20. byte segment2;
  21. byte znak[8];
  22. unsigned int jas = 15;
  23. unsigned int jas_old = 15;
  24. byte pin_aud = 8;
  25. unsigned int ton1 = 3000;
  26.  
  27. // definování znaků
  28. byte nula[8] = {B00111100,
  29.                 B01000010,
  30.                 B01000010,
  31.                 B01000010,
  32.                 B01000010,
  33.                 B01000010,
  34.                 B01000010,
  35.                 B00111100,};
  36.  
  37. byte jedna[8] = {0x08,
  38.                  0x18,
  39.                  0x28,
  40.                  0x08,
  41.                  0x08,
  42.                  0x08,
  43.                  0x08,
  44.                  0x08,};
  45.                  
  46. byte dva[8] = {0x3C,
  47.                0x42,
  48.                0x02,
  49.                0x04,
  50.                0x18,
  51.                0x20,
  52.                0x42,
  53.                0x7E,};
  54.                
  55. byte tri[8] = {0x3C,
  56.                0x42,
  57.                0x02,
  58.                0x1C,
  59.                0x02,
  60.                0x02,
  61.                0x42,
  62.                0x3C,};    
  63.  
  64. byte ctyri[8] = {0x08,
  65.                  0x18,
  66.                  0x28,
  67.                  0x48,
  68.                  0x7E,
  69.                  0x08,
  70.                  0x08,
  71.                  0x08,};
  72.              
  73. byte pet[8] = {0x7E,
  74.                0x40,
  75.                0x40,
  76.                0x7C,
  77.                0x02,
  78.                0x02,
  79.                0x42,
  80.                0x3C,};  
  81.                
  82. byte sest[8] = {0x3C,
  83.                0x40,
  84.                0x40,
  85.                0x7C,
  86.                0x42,
  87.                0x42,
  88.                0x42,
  89.                0x3C,};  
  90.                
  91. byte sedum[8] = {0x7E,
  92.                0x42,
  93.                0x04,
  94.                0x04,
  95.                0x08,
  96.                0x10,
  97.                0x10,
  98.                0x20,};
  99.  
  100. byte osum[8] = {0x3C,
  101.                0x42,
  102.                0x42,
  103.                0x3C,
  104.                0x42,
  105.                0x42,
  106.                0x42,
  107.                0x3C,};
  108.  
  109. byte devet[8] = {0x3C,
  110.                0x42,
  111.                0x42,
  112.                0x3C,
  113.                0x02,
  114.                0x02,
  115.                0x42,
  116.                0x3C,};                
  117.  
  118. void setup()
  119. {
  120.   jas = analogRead(A0);
  121.   jas = 15-(jas/68);
  122.   lc.shutdown(0,false);// turn off power saving, enables display
  123.   lc.setIntensity(0,jas);// sets brightness (0~15 possible values)
  124.   lc.clearDisplay(0);// clear screen
  125.   lc.shutdown(1,false);// turn off power saving, enables display
  126.   lc.setIntensity(1,jas);// sets brightness (0~15 possible values)
  127.   lc.clearDisplay(1);// clear screen
  128.   sensors.begin();
  129.   Serial.begin(9600);
  130. }
  131.  
  132. void loop()
  133. {
  134.   // Nastavení jasu disp.
  135.   jas = analogRead(A0);
  136.   jas = 15-(jas/68);
  137.   if (jas != jas_old) {
  138.   lc.setIntensity(0,jas);// sets brightness (0~15 possible values)
  139.   lc.setIntensity(1,jas);// sets brightness (0~15 possible values)
  140.   jas_old =jas;
  141.   }
  142.  
  143.    sensors.requestTemperatures();
  144.    teplota = sensors.getTempCByIndex(0);
  145.  
  146.    if (teplota < 0) teplota = 0;
  147.    if (teplota > 99) teplota = 99;
  148.    
  149. if (teplota > 29 || teplota == 0) {
  150.  
  151.    segment1 = teplota / 10;
  152.    segment2 = teplota - (segment1*10);
  153.    
  154.    // Zápis segmentu 1
  155.    if (segment1 == 0) memcpy( znak, nula, 8);
  156.    if (segment1 == 1) memcpy( znak, jedna, 8);
  157.    if (segment1 == 2) memcpy( znak, dva, 8);
  158.    if (segment1 == 3) memcpy( znak, tri, 8);
  159.    if (segment1 == 4) memcpy( znak, ctyri, 8);
  160.    if (segment1 == 5) memcpy( znak, pet, 8);
  161.    if (segment1 == 6) memcpy( znak, sest, 8);
  162.    if (segment1 == 7) memcpy( znak, sedum, 8);
  163.    if (segment1 == 8) memcpy( znak, osum, 8);
  164.    if (segment1 == 9) memcpy( znak, devet, 8);
  165.    for (byte row=0; row <= 7; row++){
  166.      for (byte col=0; col <= 7; col++){
  167.        lc.setLed(0,col,row, bitRead(znak[row], col));
  168.      }
  169.    }  
  170.    
  171.    // Zápis segmentu 2
  172.    if (segment2 == 0) memcpy( znak, nula, 8);
  173.    if (segment2 == 1) memcpy( znak, jedna, 8);
  174.    if (segment2 == 2) memcpy( znak, dva, 8);
  175.    if (segment2 == 3) memcpy( znak, tri, 8);
  176.    if (segment2 == 4) memcpy( znak, ctyri, 8);
  177.    if (segment2 == 5) memcpy( znak, pet, 8);
  178.    if (segment2 == 6) memcpy( znak, sest, 8);
  179.    if (segment2 == 7) memcpy( znak, sedum, 8);
  180.    if (segment2 == 8) memcpy( znak, osum, 8);
  181.    if (segment2 == 9) memcpy( znak, devet, 8);
  182.    for (byte row=0; row <= 7; row++){
  183.      for (byte col=0; col <= 7; col++){
  184.        lc.setLed(1,col,row, bitRead(znak[row], col));
  185.      }
  186.    }  
  187. }
  188. else {
  189.   lc.clearDisplay(0);// clear screen
  190.   lc.clearDisplay(1);// clear screen
  191.   lc.setLed(1,0,7,1);
  192. }
  193.      
  194. // --- signalizace přehřátí ------------------------
  195.  if (teplota > 85) {
  196.    for(a=0; a<3; a++) {
  197.      tone(pin_aud, ton1, 100);
  198.      delay(200);
  199.    }
  200.    for(a=0; a<3; a++) {
  201.      tone(pin_aud, ton1, 300);
  202.      delay(400);
  203.    }
  204.    for(a=0; a<3; a++) {
  205.      tone(pin_aud, ton1, 100);
  206.      delay(200);
  207.    }
  208.    noTone(pin_aud);
  209.  }
  210.  
  211.    delay(5000);
  212. }