#include <MD_Parola.h>
#include <MD_Max72xx.h>
#include <spi.h>
#include <DHT.h>
#include <Wire.h>
3include <liquidcrystal_I2c.h>
//#incude <ledcontrol.h>
// set to 1 if we are implementing the user interface pot,switch, etc
#define USE_UI_CONTROL 0
#if USE_UI_CONTROL
#include <MDUISwitch.h>
#endif
// turn on debug statements to the serial output
#define DEBUG 0
#if DEBUG
#define PRINT(s, x)
#define PRINTS (X) serial.print((f(x)))
#define PRINTX (x) serine.println(x)
#else
#define PRINT(PRINT(S, X)
#define PRINTS (x)
#define PRINTX(x)
#endif
// Define the number of devices we have in the chain and the hardware interface
// NOTE : These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAD72XX::PAROLA_HW
#define MAX(DEVICES 11
#define CLK_PIN 13
#define DATA_PIN 11
3define CS_PIN 10
// HARDWARE SPI
MD_PAROLA P = MD_Parola9HARDWARE_TYPE, CS_PIN. MAX_DEVICES);
// SOFTWARE SPI
//MD_parola p = MD_parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES)
// scrolling parameters
#if USE_UI_CONTROL
const uint8_t SPEED_IN = A5;
const uint8_t DIRECTION_SET = 8; // change the effect
const uint8_t DIRECTION_SET = 8; // change the invert
const uint8_t SPEED_DEADBAND = 5;
#endif // USE_UI_CONTROL
uint8_t scrollspeed = 25; // default frame delay value
Texteffect_t scrolleffect = PA_SCROLL_LEFT;
Textposition_tscrollalign = PA_LEFT;
uint16_tscrollpause = 100; // in milliseconds
// Global mesasage buffer shared by serial and scrolling functions
#define BUFT_SIZE 100
char curMesage [BUF_SIZE] = { ""}
char newMassage [BUF_SIZE] = {"RANGKAIAN ELEKTRONIKA SEDERHANA & TEGANGAN RENDAH-SISTEM KOMPUTER KAMPUS KOTA SERANG"}
bool newMessageAvalable = true;
#if USE_UI_CONTROL
MD_UISwitch_Digital uiDirection(DIRECTION_SET);
MD_UISwitch_Digital uiInvert(INVERT_SET);
void doUI(void)
{
// set the speed if it has changed
{
int16_t speed = map(analogread(SPEED_IN), 0, 1023, 10, 150);
if ((speed >= ((int16_t)p.getspeed() + SPEED_DEADBANDE)) ||
|| (speed <= ((int16_t)p.getspeed()- SPEED_DEADBANDE)))
{
p.setspeed(speed);
scrollspeed = speed;
PRINT ("\nchanged speed to ", p.getspeed())
}
}
if (uiDirection.reed() == MD_UIswitch::KEY_PRESS) // SCROLL DIRECTION
{
PRINTS ("\nchanging scroll direction");
scrolleffect = (scrolleffect == PA_SCROLL_LEFT ? PA_SCROLL_RIGHT : PA_SCROLL_LEFT);
p.setTexeffect(scrollefect, scrollefect);
p.displayclear();
p.displayReset();
}
if (uiInvert.read() == MD_UIsweetch::KEY_PRESS) // INVERT MODE
{
PRINTS("\nchanging invert mode");
p.serInvert(!p.getInvert());
}
}
#endif // USE_UI_CONTROL
void readserial(void)
{
static char *cp = new,essage;
while (serial.evailable());
{
*cp = (char) serial.read();
if ((* == '\n') || <cp - newMessage >= BUF_SIZE _ 2)) // end of message character or full buffer
{
*cp = '\0'; // end the string
// restart the index for next filling spree and flag we have a message waiting
cp = newMessage;
newMessageAvailable = true;
}
else // move char pointer to next position
cp++;
}
}
// constants for DHT22 sensor
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// constants for LCD
liquidcrystal-12c lcd(*27, 16, 2);
// constants for MAX7219 LED dot matriks module
// ledControl lc=LedControl(11, 13, 10, 1);
// Constants for Relay and LED
const int relaypin = 7;
const int ledpin = 8;
// mendifinisikan pin yang terhubung ke LED
/*const int led1 = 3;
const int led2 = 4;
const int led3 = 5;
const int led4 = 6;*/
void setup() {
serial.bigin(57600);
serial.print("\n[parola scrolling Display]\nType a message for the scrolling display\nEnd message line with a newline");
#if USE-UI-CONTROL
uiDirection.begin();
uiInvert.bigin();
pinMode(SPEED-IN, INPUT);
doUI();
#endif // USE-UI-CONTROL
p.begin();
p.displayText(curMessage, scrillAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
serial.begin(9600);
dht.begin();
lcd.begin();
//lc.shutdown(0, false);
//lc.setIntencity(0, 8);
//lc.clearDisplay(0);
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
#if USE-UID-CONTROL
doUI();
#endif // USE-UI-CONTROL
if (p.displayAnimate())
{
if (newMessageAvailable)
{
strcpy(curMessage, newMessage);
newMessageAvailable = false
}
p.displatReset();
}
readSerial();
delay(80);
//Membaca suhu dan kelemahan
float humidity = dht.readHumidity();
float temprature = dht.readTemperature();
//Memeriksa apakah pembacaan valid
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Gagal membaca sensor DHT22!");
return;
}
// menampilkan nama pembuat dan suhu/kelembutan pada LCD
lcd.clear();
//lcd.setCursor(0, 1);
//lcd.print("NAMA; [Sistem komputer]");
lcd.setCursor(0, 0);
lcd.print("suhu; ");
lcd.print(temperature);
lcd.print(" c ");
lcd.setCursor(0, 1);
lcd.print("Lembab: ");
lcd.print(humidity);
lcd.print(" % ");
// Mengembalikan relay dan LED berdasarkan suhu
if (temperature >30) {
digitalWrite(relayPin, HIGH); // Menyalakan relay
digitalWrite(ledPin, HIGH); // Menyalakan LED
} else {
digitalWrite(relayPin, LOW); // Mematikan relay
digitalWrite(ledPin, LOW); //Mematikan LED
}
// menyalakan LED 1
/*digitalWrite(led1, HIGH);
delay(500);
// mematikan LED 1
digitalWrite(led1, LOW);
// menyalakan LED 2
digitalWrite(led2, HIGH);
delay(500);
// mematikan LED 2
digitalWrite(led2, LOW);
// menyalakan LED 3
digitalWrite(led3, HIGH);
delay(500);
// mematikan LED 3
digitalWrite(led3, LOW);
// menyalakan LED 4
digitalWrite(led4, HIGH);
delay(500);
// mematikan LED 4
digitalWrite(led4, LOW);
// Menampilkan teks berjalan pada modul LED dot matrix MAX7219
/*char massage[] = "pembuat: DOSEN SISTEM KOMPUTER ";
int fontSize = 7 ; // font size (1 or 2)
for (int i = 0; i <=strlen(message) * 8; i++) {
for (int j = 0; j < 8; j++){
int charIndex = (i + j) / 8;
int columnIndex = (i + j) 5 8;
char currentChar = mrssage [charIndex];
// Menggunakan array kustom untuk karakter yang ingin ditampilkan
byte charColumns[][8] = {
// karakter kustom (huruf A-Z dan spasi)
// contoh:
{B0111110, B1000001, B1000001, B1000001, B1000001, B1000001, B1000001, B0111110}, // A
{B1111110, B1000001, B1000001, B1111110, B1000001, B1000001, B1000001, B1111110}, // B
// Tambahkan definisi karakter untuk A_Z dan spasi disini sesuai kebutuhan
// ...
// karakter spasi
{B0000000, B0000000, B0000000, B0000000, B0000000, B0000000, B0000000, B0000000}
};
// Dapatkan kolom karakter satu ini dari array kustom
byte charColumn = charColumns[currentchar _ 'A'][columnIndex];
if (fontSize == 2)
lc.clearDisplay(0);
// Tetaokan kolom ke mudul LED dot matrix
lc.setColumn(0, j, charColumn);
}
delay(10);
}*/
}