I have the following code problem, when I add a frequency sensor and the P10 LED won't work but when I just add normal writing the P10 LED will work?
no work
#include <DMDESP.h>
#include <fonts/ElektronMart6x8.h>
// SETUP DMD
#define DISPLAYS_WIDE 2 // Kolom Panel
#define DISPLAYS_HIGH 1 // Baris Panel
DMDESP Disp(DISPLAYS_WIDE, DISPLAYS_HIGH); // Jumlah Panel P10 yang digunakan (KOLOM, BARIS)
int input = D4;
int high;
int low;
float time_period;
float periode;
float frekuensi;
unsigned long previousMillis = 0;
unsigned long interval = 500;
void setup() {
pinMode(input, INPUT);
Serial.begin(115200);
Disp.start();
Disp.setBrightness(255);
Disp.setFont(ElektronMart6x8);
}
void loop() {
Disp.loop();
high = pulseIn(input, HIGH);
low = pulseIn(input, LOW);
if (millis() - previousMillis >= interval) {
previousMillis = millis();
time_period = high + low;
periode = time_period / 900.0; // pastikan pembagian dengan float
if (periode > 0) { // untuk menghindari pembagian dengan nol
frekuensi = 1000.0 / periode;
} else {
frekuensi = 0;
}
Disp.clear(); // membersihkan tampilan sebelumnya
Disp.drawText(1, 0, String(frekuensi)); // menampilkan frekuensi pada posisi (1,0)
Disp.drawText(8, 8, "Hz"); // menampilkan "Hz" pada posisi (8,8)
Serial.print("Frekuensi: ");
Serial.print(frekuensi);
Serial.println(" Hz");
}
}
work
#include <DMDESP.h>
#include <fonts/ElektronMart6x8.h>
//SETUP DMD
#define DISPLAYS_WIDE 2 // Kolom Panel
#define DISPLAYS_HIGH 1 // Baris Panel
DMDESP Disp(DISPLAYS_WIDE, DISPLAYS_HIGH); // Jumlah Panel P10 yang digunakan (KOLOM,BARIS)
int input = D4;
int high;
int low;
float time_period;
float periode;
float frekuensi;
float inf = 50.03;
void setup() {
pinMode(input, INPUT);
Serial.begin(115200);
Disp.start();
Disp.setBrightness(255);
Disp.setFont(ElektronMart6x8);
}
void loop() {
Disp.loop();
Disp.drawText(0,0,"DMDESP");
}