
Arduino 上手教程
环境配置: 参考 Arduino IDE 上手教程完成 IDE 安装,并根据实际使用的开发板安装对应的板管理,与需要的驱动库。
使用到的驱动库:
使用到的硬件产品:


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