#include <OneWire.h>
#include <DallasTemperature.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// DS18B20 setup
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Define hardware type, size, and pins for MAX7219
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW // Adjust according to your module
#define MAX_DEVICES 1 // Number of MAX7219 devices (LED matrices)
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
// Create a Parola object for text display
MD_Parola parola = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
void setup() {
Serial.begin(9600);
// Start up the DS18B20 sensor library
sensors.begin();
// Initialize the Parola display
parola.begin();
parola.setIntensity(8); // Set brightness level (0 is min, 15 is max)
parola.displayClear(); // Clear display
// Set the text alignment to center and the scrolling direction
parola.setTextAlignment(PA_LEFT); // Correct the text orientation
}
void loop() {
// Request temperature from the sensor
sensors.requestTemperatures();
// Fetch temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Print the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
// Convert the temperature to a string
String tempString = "Temp: " + String(temperatureC, 1) + "C";
// Display the temperature on the LED matrix
displayScrollingText(tempString.c_str());
delay(1000); // Update every second
}
void displayScrollingText(const char* msg) {
// Set up scrolling parameters with the correct direction
parola.displayText(msg, PA_LEFT, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
// Start displaying the scrolling text
while (!parola.displayAnimate()) {
// Animate the text
}
}