
Arduino 上手教程
环境配置: 参考 Arduino IDE 上手教程完成 IDE 安装,并根据实际使用的开发板安装对应的板管理,与需要的驱动库。
使用到的驱动库:
使用到的硬件产品:
 
 
G2。
 writeMicroseconds 函数控制舵机的转动位置,适用于 Servo Kit 180° 和 Servo Kit 360°。其中 COUNT_LOW 和 COUNT_HIGH 分别对应舵机的最小和最大脉冲宽度,STEP 定义了脉冲宽度的增量步长,SERVO_PIN 定义了连接舵机信号线的数字引脚。COUNT_LOW 通常对应舵机的 0° 位置,COUNT_HIGH 对应 180° 位置。使用 writeMicroseconds 函数后,舵机会根据传入的脉冲宽度值转动到相应的位置且维持在该位置,下方例程中 servo.writeMicroseconds(1500) 会使 Servo Kit 180° 转动到 90° 位置并保持。writeMicroseconds 函数中传入的值控制舵机的旋转速度和方向,COUNT_LOW 对应逆时针最大速度,COUNT_HIGH 对应顺时针最大速度,而中间值则表示停止转动。COUNT_LOW ~ 中间值范围内为逆时针转动,数值越大舵机旋转速度越快;中间值 ~ COUNT_HIGH范围内为顺时针转动,数值越大舵机旋转速度越慢,下方例程中servo.writeMicroseconds(1500) 会使 Servo Kit 360° 维持停止状态。#include "M5Unified.h"
#include "M5GFX.h"
#include "ESP32Servo.h"       
// Macro definitions for servo control parameters
#define COUNT_LOW  500     // Minimum pulse width in microseconds (μs) for the servo (typically corresponds to 0° position)
#define COUNT_HIGH 2500    // Maximum pulse width in microseconds (μs) for the servo (typically corresponds to 180° position)
#define STEP       100      // Increment step for pulse width (controls how smoothly the servo moves between positions)
#define SERVO_PIN  2       // Digital pin connected to the servo motor's signal wire
Servo servo;              
void setup() {
  M5.begin();
  servo.attach(SERVO_PIN, COUNT_LOW, COUNT_HIGH); // Attach the servo to the specified pin, with defined min (COUNT_LOW) and max (COUNT_HIGH) pulse widths
  M5.Lcd.setFont(&fonts::FreeMonoBoldOblique12pt7b);
  M5.Lcd.drawCenterString("SERVO", 160, 110);
}
void loop() {
  servo.writeMicroseconds(500); 
  delay(2000);
  servo.writeMicroseconds(1500); // 90° for 180° Kit, Stop for 360° Kit
  delay(2000);
  servo.writeMicroseconds(2500);
  delay(2000);
  servo.writeMicroseconds(1500); // 90° for 180° Kit, Stop for 360° Kit
  delay(2000);
}1. 下载模式:不同设备进行程序烧录前需要下载模式,不同的主控设备该步骤可能有所不同。详情可参考Arduino IDE上手教程页面底部的设备程序下载教程列表,查看具体的操作方式。
AtomS3R 长按复位按键 (大约 2 秒) 直到内部绿色 LED 灯亮起,便可松开,此时设备已进入下载模式,等待烧录。