#include <DHT.h>
#include <LedControl.h>
// === Pin & Object ===
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// LedControl(DIN, CLK, CS, #Devices)
LedControl lc = LedControl(11, 13, 10, 1);
// Pin sesuai gambar: DIN=11, CLK=13, CS=10
void setup() {
Serial.begin(9600);
dht.begin();
// Inisialisasi Dot Matrix
lc.shutdown(0, false); // Wake up display
lc.setIntensity(0, 8); // Brightness level (0-15)
lc.clearDisplay(0); // Clear display
}
void loop() {
float suhu = dht.readTemperature();
if (isnan(suhu)) {
Serial.println("Gagal membaca DHT22");
return;
}
Serial.print("Suhu: ");
Serial.print(suhu);
Serial.println(" C");
// Konversi suhu ke teks
char buffer[10];
dtostrf(suhu, 4, 1, buffer); // 4 digit, 1 angka desimal
strcat(buffer, "C");
tampilkanTeks(buffer);
delay(2000);
}
// Fungsi untuk menampilkan teks ke matrix (statik)
void tampilkanTeks(const char* teks) {
lc.clearDisplay(0);
for (int i = 0; teks[i] != '\0' && i < 8; i++) {
lc.setChar(0, 7 - i, teks[i], false); // posisi dari kanan ke kiri
}
}