【电机控制器】ESP32-C3芯片——PWM、ADC

【电机控制器】ESP32-C3芯片——PWM @TOC 前言 使用工具: 1.编译器——Arduino 2.ESP32-C3最小核心板 提示:以下是本篇文章正文内容,下面案例可供参考 一、原理图 1.串口烧录 2.MCU主控和晶振 3.TYPEC-USB 4.LDO 5-3.3 5.按键 6.LED 7.FLASH 8.PWM 二、软件例程——呼吸灯 1.PWM呼吸灯 /* Fade This example shows how to fade an LED on pin 9 using the analogWrite() function. The analogWrite() function uses PWM, so if you want to change the pin you're using, be sure to use another PWM capable pin. On most Arduino, the PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11. This example code is in the public domain. https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade */ int led = 12; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by // the setup routine runs once when you press reset: void setup() { // declare pin 9 to be an output: pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // set the brightness of pin 9: analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness = 255) { fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect delay(30); } 2.ADC采样 void setup() { // initialize serial communication at 115200 bits per second: Serial.begin(115200); //set the resolution to 12 bits (0-4096) analogReadResolution(12); } void loop() { // read the analog / millivolts value for pin 2: int analogValue = analogRead(1); int analogVolts = analogReadMilliVolts(2); // print out the values you read: Serial.printf("ADC analog value = %d\n",analogValue); Serial.printf("ADC millivolts value = %d\n",analogVolts); delay(100); // delay in between reads for clear read from serial } 三、实验结果 四、参考资料 ESP32C3-CORE开发板 【esp32c3配置arduino IDE教程】 解决Arduino IDE无法安装esp32的问题 2024年12月23日更新 总结 本文仅仅简单介绍了【电机控制器】ESP32-C3芯片——PWM,评论区欢迎讨论。

Mar 28, 2025 - 07:36
 0
【电机控制器】ESP32-C3芯片——PWM、ADC

【电机控制器】ESP32-C3芯片——PWM

@TOC

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

前言

使用工具:
1.编译器——Arduino
2.ESP32-C3最小核心板

提示:以下是本篇文章正文内容,下面案例可供参考

一、原理图

在这里插入图片描述

1.串口烧录

在这里插入图片描述

2.MCU主控和晶振

在这里插入图片描述

3.TYPEC-USB

在这里插入图片描述

4.LDO 5-3.3

在这里插入图片描述

5.按键

在这里插入图片描述

6.LED

在这里插入图片描述

7.FLASH

在这里插入图片描述

8.PWM

在这里插入图片描述

二、软件例程——呼吸灯

1.PWM呼吸灯

/*
  Fade

  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.

  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
  are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
*/

int led = 12;         // the PWM pin the LED is attached to
int brightness = 0;  // how bright the LED is
int fadeAmount = 5;  // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}


2.ADC采样


void setup() {
  // initialize serial communication at 115200 bits per second:
  Serial.begin(115200);

  //set the resolution to 12 bits (0-4096)
  analogReadResolution(12);
}

void loop() {
  // read the analog / millivolts value for pin 2:
  int analogValue = analogRead(1);
  int analogVolts = analogReadMilliVolts(2);

  // print out the values you read:
  Serial.printf("ADC analog value = %d\n",analogValue);
  Serial.printf("ADC millivolts value = %d\n",analogVolts);

  delay(100);  // delay in between reads for clear read from serial
}


三、实验结果

在这里插入图片描述

四、参考资料

ESP32C3-CORE开发板
【esp32c3配置arduino IDE教程】
解决Arduino IDE无法安装esp32的问题 2024年12月23日更新

总结

本文仅仅简单介绍了【电机控制器】ESP32-C3芯片——PWM,评论区欢迎讨论。