Hodiny po 5 minútach začnú preblikávať neviem nato prísť prečo.
Kód: Vybrat vše
#include <SPI.h>
#include <DMD2.h>
/*#include <DMD.h>
DMD display(2,1);
ISR(TIMER1_OVF_vect)
{
display.refresh();
}*/
//#include <fonts/hodiny10m2.h>
//#include <fonts/hodiny11m2.h>
#include <fonts/hodiny12m2.h>
//#include <fonts/Arial_Black_16.h> //vyska 12 sirka10
//#include <fonts/hodiny2.h> //hodiny dva tenke upravit rohy
//#include <fonts/hodiny6.h> //je hotovy vyska 14 bodov
//#include <fonts/hodiny3.h> //vyska 16 bodov
#include <fonts/hodiny4.h> //zatial ok vyska 16 bodov
//#include <fonts/SystemFont5x7.h>
//#include <fonts/hodiny5.h>
//#include <fonts/hodiny7tenke1.h>
#define DEBUG 0
// pre uno ak sa pouzova SoftDMD plati aj pre megu
#define DMD_PIN_NOE 9
#define DMD_PIN_A 6
#define DMD_PIN_B 7
#define DMD_PIN_SCK 8
#define DMD_PIN_CLK 13 //sck
#define DMD_PIN_R 11 //miso
//plati pre megu ak sa pouziva SPIDMD
/*#define DMD_PIN_NOE 9
#define DMD_PIN_A 6
#define DMD_PIN_B 7
#define DMD_PIN_SCK 8
#define DMD_PIN_CLK 52 //sck
#define DMD_PIN_R 51 //miso
*/
#define DISPLAYS_WIDE 2
#define DISPLAYS_HIGH 1
//SoftDMD dmd(DISPLAYS_WIDE,DISPLAYS_HIGH);
SPIDMD dmd(DISPLAYS_WIDE, DISPLAYS_HIGH, DMD_PIN_NOE, DMD_PIN_A, DMD_PIN_B, DMD_PIN_SCK);
//SoftDMD dmd(DISPLAYS_WIDE, DISPLAYS_HIGH, DMD_PIN_NOE, DMD_PIN_A, DMD_PIN_B, DMD_PIN_SCK, DMD_PIN_CLK, DMD_PIN_R);
unsigned long previousMillis = 0 , iinterval = 1000;
int addsehen = 1;
int cle_a, cle_b;
String reserialData;
String hodMinu = "0:00";
String denMesi = "12.12.18";
String tepStup1 = "-22°C";
String tepStup2 = "-22°C";
String cistyznak = "<";
void setup() {
Serial.begin(9600);
/*display.setBrightness(map(100, 0, 100, 0, 255)); //jas max255
display.setFont(hodiny12m2);
display.drawText(0, 0, F("00:00"));
*/
dmd.selectFont(hodiny12m2);
dmd.begin();
dmd.setBrightness(map(100, 0, 100, 0, 255)); //jas max255 dmd.setBrightness(80);
dmd.drawString(17, 0, "00:00");
delay(1000);
}
void loop() {
//DMDFrame current_generation(dmd);
// jas dmd fotorezistor
//smartdelay(250);//smartdelay(1000);
reserialData = Serial.readStringUntil('\r');//Serial2.readString(); //22:22;22.22.22;-25;25;1;
Serial.println("reserialData");
Serial.println(reserialData);
//hodMinu = sgetValue(reserialData, ';', 0);
//denMesi = sgetValue(reserialData, ';', 1);
//tepStup1 = sgetValue(reserialData, ';', 2);
//tepStup2 = sgetValue(reserialData, ';', 3);
//jeSignalgps(sgetValue(reserialData, ';', 4).toInt());
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > iinterval) {
previousMillis = currentMillis;
//iinterval = 1500;
addsehen++;
}
Serial.print("Prepinac switch");
Serial.println(addsehen);
switch (addsehen) {
case 1: //hodiny //10:01 // 1:01
clerdmdPom(1);//cle_a = 1;
iinterval = 40000; //40sek
hodMinu = sgetValue(reserialData, ';', 0);
hodMinu = hodCisty(hodMinu);
//Serial.print("hodMinu");
Serial.println(hodMinu);
//display.drawText(15, 0, "00:00");
//display.drawText(15, 0, hodCisty(hodMinu));
//hodMinu = "00:00";
dmd.drawString(15, 0, hodMinu); //dmd.drawString(15, 0, hodCisty(hodMinu));
break;
case 2: //datum //12.12 // 1.1. // 2.10 //10.1.
//cle_a = 2;
iinterval = 10000; //10sek
denMesi = sgetValue(reserialData, ';', 1);
//Serial.print("denMesi");
Serial.println(denMesi);
//Serial.println(denMesi.length());
int xpor;
//denMesi = "10.10.19";
if (denMesi.length() == 8) {
xpor = 5; //61 61 21 61 61 21 61 6
//8 8 4 8 8 4 8 8
} else if (denMesi.length() == 7) {
xpor = 9; //61 21 61 61 21 61 6
clerdmdPom(2);//cle_a = 2;
} else if (denMesi.length() == 6) {
xpor = 13; //61 21 61 21 61 6
clerdmdPom(-2);//cle_a = -2;
} else if (denMesi.length() < 6) {
denMesi = "99.99.99";
xpor = 5; //61 21 61 21 61 6
clerdmdPom(-3);//cle_a = -3;
} else {
clerdmdPom(-4);//cle_a = -4;
}
//display.drawText(xpor, 0, denMesi);
dmd.drawString(xpor, 0, denMesi);
break;
case 3: //teplota, vlhkost //-10°C // -1°C // 20°C // 5°C
clerdmdPom(3);//cle_a = 3;
iinterval = 10000; //10sek
tepStup1 = sgetValue(reserialData, ';', 2);
/*
Serial.print("tepStup1");
Serial.println(tepStup1);
*/
//display.drawText(30, 0, teplota_str(tepStup1.toInt()));
//display.drawText(0, 0, "IN");
dmd.drawString(0, 0, "IN");
dmd.drawString(30, 0, teplota_str(tepStup1.toInt()));
//}
break;
case 4: //teplota, vlhkost //-10°C // -1°C // 20°C // 5°C
clerdmdPom(4);//cle_a = 3;
iinterval = 10000; //10sek
tepStup2 = sgetValue(reserialData, ';', 3);
/*
Serial.print("tepStup2");
Serial.println(tepStup2);
*/
//display.drawText(0, 0, "OUT");
//display.drawText(30, 0, teplota_str(tepStup2.toInt()));
dmd.drawString(0, 0, "OUT");
dmd.drawString(30, 0, teplota_str(tepStup2.toInt()));
//}
break;
case 5:
case 6:
addsehen = 1;
break;
}
//iinterval = 3000;//zakomentovat potom na testovnie
}
String hodCisty(String h) {
if (h.length() < 5) { //1:23
return cistyznak + h; //prazdny znak
}
return h;
}
void clerdmdPom(int iic) {
if (iic != cle_b) {
cle_b = iic;
//display.clear();//
dmd.clearScreen(); //dmd.clearScreen();
Serial.println("CLEAN");
}
}
String teplota_str(int iia) {
if (iia > -1 && iia < 10 ) { //5
return cistyznak + cistyznak + String(iia) + "'C";
}
if (iia > 9 ) { //22
return cistyznak + String(iia) + "'C";
}
if (iia < 0 && iia > -10 ) { //-5
return cistyznak + String(iia) + "'C";
}
if (iia < -9) { //-12
return String(iia) + "'C";
}
return "";
}
void jeSignalgps(int ddv) {
if (ddv==0) { //if(!gps.date.isValid() && !gps.time.isValid()){
//display.setPixel(31,15, 1); //pravo dole
dmd.setPixel(31, 15, GRAPHICS_ON); //pravo dole
}
}
String sgetValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length()-1;
for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
String getStringPartByNr(String data, char separator, int index)
{
// spliting a string and return the part nr index
// split by separator
int stringData = 0; //variable to count data part nr
String dataPart = ""; //variable to hole the return text
for (int i = 0; i < data.length() - 1; i++) { //Walk through the text one letter at a time
if (data[i] == separator) {
//Count the number of times separator character appears in the text
stringData++;
} else if (stringData == index) {
//get the text when separator is the rignt one
dataPart.concat(data[i]);
} else if (stringData > index) {
//return text and stop if the next separator appears - to save CPU-time
return dataPart;
break;
}
}
//return text if this is the last part
return dataPart;
}