#include <LedControl.h> // Library untuk mengontrol Dot Matrix 8x8
#define DATA_IN 2 // Pin DIN
#define LOAD 3 // Pin CS
#define CLK 4 // Pin CLK
#define MAX_DEVICES 1 // Jumlah modul matriks 8x8 yang digunakan
LedControl lc = LedControl(DATA_IN, CLK, LOAD, MAX_DEVICES);
int soilMoisturePin = A0;
int soilWetLimit = 245;
int soilDryLimit = 250;
byte emoticonLove[8] = {
0b01100110,
0b11111111,
0b11111111,
0b11111111,
0b01111110,
0b00111100,
0b00011000,
0b00000000
};
byte emoticonSad[8] = {
0b00111100,
0b01000010,
0b10100101,
0b10000001,
0b10011001,
0b10100101,
0b01000010,
0b00111100
};
void setup() {
Serial.begin(9600);
for (int i = 0; i < MAX_DEVICES; i++) {
lc.shutdown(i, false); // Aktifkan matriks
lc.setIntensity(i, 8); // Tentukan intensitas (terang)
lc.clearDisplay(i); // Bersihkan tampilan awal
}
}
void loop() {
int soilMoistureValue = analogRead(soilMoisturePin);
Serial.print("Soil Moisture Value: ");
Serial.println(soilMoistureValue);
if (soilMoistureValue < soilWetLimit) {
displayEmoticon(emoticonLove);
Serial.println("Tanah Basah, Menampilkan Emotikon Love");
} else if (soilMoistureValue > soilDryLimit) {
displayEmoticon(emoticonSad);
Serial.println("Tanah Kering, Menampilkan Emotikon Sedih");
}
delay(1000); // Delay 1 detik sebelum membaca lagi
}
void displayEmoticon(byte emoticon[8]) {
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, emoticon[i]); // Menampilkan setiap baris di matrix
}
}