
Arduino Quick Start
Environment Configuration: Refer to the Arduino IDE Quick Start Tutorial to install the IDE, add the board manager entries for your board, and install any required drivers and libraries.
Required driver libraries:
Hardware used:


G5 (SIGNAL).#include "M5Unified.h"
#define SIGNAL 5 // PWM signal output pin
int freq = 10000; // 10kHz
int resolution = 10; // Duty cycle resolution in bits (10-bit = 0 to 1023)
void setup() {
M5.begin();
M5.Display.setTextColor(GREEN);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::Orbitron_Light_24);
M5.Display.drawString("PWM", M5.Display.width() / 2, M5.Display.height() / 2);
ledcAttach(SIGNAL, freq, resolution);// Bind the pin, frequency, and resolution
}
void loop() {
for (int i = 0; i < 500; i++) {
ledcWrite(SIGNAL, i);// Update the PWM duty cycle
delay(2);
}
for (int i = 500; i > 0; i--) {
ledcWrite(SIGNAL, i);
delay(2);
}
}