Arduino ESP32入门点灯程序

Posted perseverance52

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Arduino ESP32入门点灯程序相关的知识,希望对你有一定的参考价值。

Arduino ESP32入门点灯程序

  • 点灯前提是,你需要提前安装esp32支持固件包。
  • ESP32开发资料1.74G,从入门到入土。
链接: https://pan.baidu.com/s/1kSxiO9kwWGMhzr6WCPdVYw  
提取码:8x8m
  • 示例程序:

  • 呼吸灯效果

示例程序需要修改板子led引脚:5 引脚---->2引脚

/*
 LEDC Software Fade

 This example shows how to software fade LED
 using the ledcWrite function.

 Code adapted from original Arduino Fade example:
 https://www.arduino.cc/en/Tutorial/Fade

 This example code is in the public domain.
 */

// use first channel of 16 channels (started from zero)
#define LEDC_CHANNEL_0     0

// use 13 bit precission for LEDC timer
#define LEDC_TIMER_13_BIT  13

// use 5000 Hz as a LEDC base frequency
#define LEDC_BASE_FREQ     5000

// fade LED PIN (replace with LED_BUILTIN constant for built-in LED)
#define LED_PIN            2	//这是需要修改的地方,将5改为2号引脚才行

int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// Arduino like analogWrite
// value has to be between 0 and valueMax
void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
  // calculate duty, 8191 from 2 ^ 13 - 1
  uint32_t duty = (8191 / valueMax) * min(value, valueMax);

  // write duty to LEDC
  ledcWrite(channel, duty);
}

void setup() {
  Serial.begin(115200);//设置串口波特率
  // Setup timer and attach timer to a led pin
  ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
  ledcAttachPin(LED_PIN, LEDC_CHANNEL_0);
}

void loop() {
  // set the brightness on LEDC channel 0
  ledcAnalogWrite(LEDC_CHANNEL_0, 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);
  Serial.println("hello world");//添加串口打印信息
}

以上是关于Arduino ESP32入门点灯程序的主要内容,如果未能解决你的问题,请参考以下文章

ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组

ESP32/ESP8266TCP异步通讯点灯控制示例程序

ESP32 WiFi-AP模式下点灯控制程序

Micropython esp32/8266网页点灯控制示例

酷易物联-arduino-sdk教程利用自动生成的sdk模板点灯和上传数据

酷易物联-arduino-sdk教程利用自动生成的sdk模板点灯和上传数据