#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
#include "LedControl.h" // need the library
LedControl lc=LedControl(12,11,10,2); //
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219, 2 is 2xMAX...
int teplota = 30;
byte a;
byte segment1;
byte segment2;
byte znak[8];
unsigned int jas = 15;
unsigned int jas_old = 15;
byte pin_aud = 8;
unsigned int ton1 = 3000;
// definování znaků
byte nula[8] = {B00111100,
B01000010,
B01000010,
B01000010,
B01000010,
B01000010,
B01000010,
B00111100,};
byte jedna[8] = {0x08,
0x18,
0x28,
0x08,
0x08,
0x08,
0x08,
0x08,};
byte dva[8] = {0x3C,
0x42,
0x02,
0x04,
0x18,
0x20,
0x42,
0x7E,};
byte tri[8] = {0x3C,
0x42,
0x02,
0x1C,
0x02,
0x02,
0x42,
0x3C,};
byte ctyri[8] = {0x08,
0x18,
0x28,
0x48,
0x7E,
0x08,
0x08,
0x08,};
byte pet[8] = {0x7E,
0x40,
0x40,
0x7C,
0x02,
0x02,
0x42,
0x3C,};
byte sest[8] = {0x3C,
0x40,
0x40,
0x7C,
0x42,
0x42,
0x42,
0x3C,};
byte sedum[8] = {0x7E,
0x42,
0x04,
0x04,
0x08,
0x10,
0x10,
0x20,};
byte osum[8] = {0x3C,
0x42,
0x42,
0x3C,
0x42,
0x42,
0x42,
0x3C,};
byte devet[8] = {0x3C,
0x42,
0x42,
0x3C,
0x02,
0x02,
0x42,
0x3C,};
void setup()
{
jas = analogRead(A0);
jas = 15-(jas/68);
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,jas);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
lc.shutdown(1,false);// turn off power saving, enables display
lc.setIntensity(1,jas);// sets brightness (0~15 possible values)
lc.clearDisplay(1);// clear screen
sensors.begin();
Serial.begin(9600);
}
void loop()
{
// Nastavení jasu disp.
jas = analogRead(A0);
jas = 15-(jas/68);
if (jas != jas_old) {
lc.setIntensity(0,jas);// sets brightness (0~15 possible values)
lc.setIntensity(1,jas);// sets brightness (0~15 possible values)
jas_old =jas;
}
sensors.requestTemperatures();
teplota = sensors.getTempCByIndex(0);
if (teplota < 0) teplota = 0;
if (teplota > 99) teplota = 99;
if (teplota > 29 || teplota == 0) {
segment1 = teplota / 10;
segment2 = teplota - (segment1*10);
// Zápis segmentu 1
if (segment1 == 0) memcpy( znak, nula, 8);
if (segment1 == 1) memcpy( znak, jedna, 8);
if (segment1 == 2) memcpy( znak, dva, 8);
if (segment1 == 3) memcpy( znak, tri, 8);
if (segment1 == 4) memcpy( znak, ctyri, 8);
if (segment1 == 5) memcpy( znak, pet, 8);
if (segment1 == 6) memcpy( znak, sest, 8);
if (segment1 == 7) memcpy( znak, sedum, 8);
if (segment1 == 8) memcpy( znak, osum, 8);
if (segment1 == 9) memcpy( znak, devet, 8);
for (byte row=0; row <= 7; row++){
for (byte col=0; col <= 7; col++){
lc.setLed(0,col,row, bitRead(znak[row], col));
}
}
// Zápis segmentu 2
if (segment2 == 0) memcpy( znak, nula, 8);
if (segment2 == 1) memcpy( znak, jedna, 8);
if (segment2 == 2) memcpy( znak, dva, 8);
if (segment2 == 3) memcpy( znak, tri, 8);
if (segment2 == 4) memcpy( znak, ctyri, 8);
if (segment2 == 5) memcpy( znak, pet, 8);
if (segment2 == 6) memcpy( znak, sest, 8);
if (segment2 == 7) memcpy( znak, sedum, 8);
if (segment2 == 8) memcpy( znak, osum, 8);
if (segment2 == 9) memcpy( znak, devet, 8);
for (byte row=0; row <= 7; row++){
for (byte col=0; col <= 7; col++){
lc.setLed(1,col,row, bitRead(znak[row], col));
}
}
}
else {
lc.clearDisplay(0);// clear screen
lc.clearDisplay(1);// clear screen
lc.setLed(1,0,7,1);
}
// --- signalizace přehřátí ------------------------
if (teplota > 85) {
for(a=0; a<3; a++) {
tone(pin_aud, ton1, 100);
delay(200);
}
for(a=0; a<3; a++) {
tone(pin_aud, ton1, 300);
delay(400);
}
for(a=0; a<3; a++) {
tone(pin_aud, ton1, 100);
delay(200);
}
noTone(pin_aud);
}
delay(5000);
}