Led p10 no working p10 wemos d1 mini

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"); 
}

For the P10 panel to work correctly, the Disp.loop() method must be called hundreds of times per second. Any delays or functions in a program that last more than a few milliseconds are unacceptable.
At the same time, the pulseIn function has a large delay that stops the entire program waiting for an incoming signal.

The pulseIn function is incompatible with the DMDESP.h library. You need to use the libraries that use an interrupts to drive the P10 panels.

Try this

#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();
  if (millis() - previousMillis >= interval) {
    previousMillis = millis();
    high = pulseIn(input, HIGH);    
    low = pulseIn(input, LOW);
    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");
  }
}

It will probably flicker, but maybe it will display the frequency.

1 Like

Or maybe continue to use this library but use interrupts to measure the frequency.

Which libraries support it?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.