/* Basic example code for MAX7219 LED dot matrix display with Arduino. More info: https://www.makerguides.com */
// Include the required Arduino libraries:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Define hardware type, size, and output pins:
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4
#define CS_PIN 3
#define CLK_PIN 13 // CLK or SCK
#define DATA_PIN 11 // DATA or MOSI
// Set temp sensor pin:
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 2
// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);
// Create a new instance of the MD_Parola class with hardware SPI connection:
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
// Start up the library:
sensors.begin();
// Setup for software SPI:
// #define DATAPIN 2
// #define CLK_PIN 4
// MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
// Intialize the object:
myDisplay.begin();
// Set the intensity (brightness) of the display (0-15):
myDisplay.setIntensity(0);
// Clear the display:
myDisplay.displayClear();
//myDisplay.displayText("Hello", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
//if (myDisplay.displayAnimate()) {
// myDisplay.displayReset();
//}
}
unsigned long startMillis;
unsigned long currentMillis;
unsigned long elapsedMillis;
bool first_run = true;
void loop() {
// Send the command for all devices on the bus to perform a temperature conversion:
sensors.requestTemperatures();
// Fetch the temperature in degrees Celsius for device index:
float t = sensors.getTempCByIndex(0); // the index 0 refers to the first device
// Fetch the temperature in degrees Fahrenheit for device index:
// Check if any reads failed and exit early (to try again):
if (isnan(t)) {
Serial.println("Failed to read from temp sensor!");
return;
}
int cele_cislo = t;
int zvysok = (t - cele_cislo) * 10;
String celsius = "C";
String bodka = ".";
String degree = "\xB0";
String teplota = cele_cislo + bodka + zvysok + degree + celsius;
int minuta = 0;
int sekunda = 0;
//stopwatch part
if (first_run == true){
//boot message
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print("boot");
delay(1000);
myDisplay.print(".boot.");
delay(1000);
myDisplay.print("..boot..");
delay(1000);
myDisplay.displayClear();
myDisplay.displayText("OTUZOVATOR model 3000", PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
while (myDisplay.displayAnimate() == false){
}
//start stopwatch
startMillis = millis();
first_run = false;
}
else {
int i = 0;
do {
currentMillis = millis();
elapsedMillis = (currentMillis - startMillis);
Serial.print("elapsedMillis: ");
Serial.print(elapsedMillis);
Serial.println("");
unsigned long durMS = (elapsedMillis%1000); //Milliseconds
unsigned long durSS = (elapsedMillis/1000)%60; //Seconds
unsigned long durMM = (elapsedMillis/(60000))%60; //Minutes
unsigned long durHH = (elapsedMillis/(3600000)); //Hours
durHH = durHH % 24;
Serial.print("Time: ");
Serial.print(durHH);
Serial.print(" : ");
Serial.print(durMM);
Serial.print(" : ");
Serial.print(durSS);
Serial.print(" : ");
Serial.print(durMS);
Serial.println("");
String durMilliSec = timeMillis(durMM, durSS);
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print(durMilliSec);
Serial.println("******************************");
Serial.println("");
delay(100);
i++;
} while (i <= 50);
//OUTPUT
Serial.println(teplota);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" \xC2\xB0");
Serial.print("C | ");
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print(teplota);
delay(2000);
}
}
String timeMillis(unsigned long Mintime,unsigned long Sectime)
{
String dataTemp = "";
if (Mintime < 10)
{
dataTemp = dataTemp + "0" + String(Mintime)+ ":";
}
else{
dataTemp = dataTemp + String(Mintime)+ ":";
}
if (Sectime < 10)
{
dataTemp = dataTemp + "0" + String(Sectime);
}
else{
dataTemp = dataTemp + String(Sectime);
}
Serial.print("String Time: ");
Serial.println(dataTemp);
return dataTemp;
}