dashboard testing — Esp32 Devkit C V4 simulation

learning

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by tzaw1591.

Components

Sketch code

#include <driver/ledc.h>
#include <Arduino.h>

#define CAM_SIGNAL_PIN (19)
#define RECEIVE_SIGNAL_PIN (18)
#define TIMER_RESOLUTION   LEDC_TIMER_10_BIT 
unsigned long timer_count = 0;

uint32_t current_duty = 0;
void signal_setup(uint32_t pin,ledc_channel_t channel,ledc_timer_t timer)
{
  ledc_timer_config_t ledc_timer = {
      .speed_mode = LEDC_LOW_SPEED_MODE,
      .duty_resolution = TIMER_RESOLUTION,
      .timer_num =timer,
      .freq_hz = 80,
      .clk_cfg = LEDC_USE_REF_TICK ,
  };

  ledc_timer_config(&ledc_timer);

  current_duty = (1 << TIMER_RESOLUTION) / 2;

  ledc_channel_config_t ledc_channel = {
      .gpio_num = pin,       
      .speed_mode = LEDC_LOW_SPEED_MODE, 
      .channel = channel,        
      .intr_type = LEDC_INTR_DISABLE,  
      .timer_sel = timer,        
      .duty = current_duty,           
      .hpoint = 0                     
  };
  ledc_channel_config(&ledc_channel);
  ledc_fade_func_install(0);
}
void update_duty_cycle(uint32_t duty,ledc_channel_t channel){
  current_duty = duty;
    ledc_set_duty(LEDC_LOW_SPEED_MODE,channel,duty);
    ledc_set_duty_and_update(LEDC_LOW_SPEED_MODE,channel,duty,0);
}
void update_freq(uint32_t freq,ledc_timer_t timer){
  ledc_set_freq(LEDC_LOW_SPEED_MODE,timer,freq);
}
void setup()
{
  Serial.begin(115200);
  pinMode(RECEIVE_SIGNAL_PIN,INPUT);
  // pinMode(CAM_SIGNAL_PIN,OUTPUT);

  // digitalWrite(CAM_SIGNAL_PIN,HIGH);

  signal_setup(CAM_SIGNAL_PIN,LEDC_CHANNEL_0,LEDC_TIMER_0);
  
  // update_freq(5,LEDC_TIMER_0);
 
  Serial.println("Cam Signal Started on PIN 19 and crank signal start on 18");
}

void loop()
{
 // Pin 18 ကို HIGH ဖြစ်လာမယ့် အချိန်အထိ စောင့်ဖတ်မယ် (Timeout 1 စက္ကန့် ပေးထားမယ်)
  unsigned long high_duration = pulseIn(RECEIVE_SIGNAL_PIN, HIGH, 1000000); 

  if (high_duration > 0) {
    // Pulse ကို ဖမ်းမိသွားပြီဆိုရင် ဘယ်လောက်ကြာလဲ (Microseconds) ဆိုတာကို ပြမယ်
    Serial.print("SUCCESS! HIGH Signal caught. Duration: ");
    Serial.print(high_duration);
    Serial.println(" microseconds");
  } else {
    // ၁ စက္ကန့်လုံးလုံး စောင့်တာတောင် HIGH မဖြစ်ရင် ဒါကို ပြမယ်
    Serial.println("Still LOW... No pulse detected.");
  }
  
  delay(100);
}