当前位置: 首页 > news >正文

感知节点@5@ ESP32+arduino+ 第三个程序FreeRTOS 上 LED灯显示 和 串口打印ASCII表

思路:

将 LED灯显示          作为 一个独立的 FreeROTS 任务
将串口打印ASCII表 作为 一个独立的 FreeROTS任务

将已经调试好的 LED灯显示代码 和  串口打印ASCII表 可以复制使用。

 

1)观看视频,理解FreeROTS 多任务运行,复制程序实例

第二课:

https://www.bilibili.com/video/BV1RB4y1Q7be/?spm_id_from=333.1387.collection.video_card.click&vd_source=25818e6e97754951f67187083c89af5a

仿真链接:

 第二课:程序实例: https://wokwi.com/projects/332576245745189459

image

 

2)复制程序实例,并修改初始化和任务函数,实现LED灯显示任务 和  串口打印ASCII表任务

/*程序: FREERTOS - 多任务点灯程序实例作业: 添加LED3公众号:孤独的二进制
*/
//查看电路图,那个ESP32的引脚连接LED灯  图中看到是IO2
#define LED_BUILTIN 2  void task1(void *pt) {//pinMode(23, OUTPUT);// initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);while (1) {//digitalWrite(23, !digitalRead(23));/*Tick to TimepdMS_TO_TICKSportTICK_PERIOD_MSvTaskDelay(pdMS_TO_TICKS(1000));vTaskDelay(1000/portTICK_PERIOD_MS);*///vTaskDelay(1000); //注意 是 ticks的数量 不是时间
digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)vTaskDelay(1000);//delay(1000);                      // wait for a seconddigitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOWvTaskDelay(1000);//delay(1000);                      // wait for a second
  }
}// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33;
void task2(void *pt) {//pinMode(21, OUTPUT);//Initialize serial and wait for port to open:Serial.begin(9600);while (!Serial) {;  // wait for serial port to connect. Needed for native USB port only
  }// prints title with ending line breakSerial.println("ASCII Table ~ Character Map");while (1) {// digitalWrite(21, !digitalRead(21));// vTaskDelay(3000);// prints value unaltered, i.e. the raw binary version of the byte.// The Serial Monitor interprets all bytes as ASCII, so 33, the first number,// will show up as '!'
  Serial.write(thisByte);Serial.print(", dec: ");// prints value as string as an ASCII-encoded decimal (base 10).// Decimal is the default format for Serial.print() and Serial.println(),// so no modifier is needed:
  Serial.print(thisByte);// But you can declare the modifier for decimal if you want to.// this also works if you uncomment it:// Serial.print(thisByte, DEC);Serial.print(", hex: ");// prints value as string in hexadecimal (base 16):
  Serial.print(thisByte, HEX);Serial.print(", oct: ");// prints value as string in octal (base 8);
  Serial.print(thisByte, OCT);Serial.print(", bin: ");// prints value as string in binary (base 2) also prints ending line break:
  Serial.println(thisByte, BIN);// if printed last visible character '~' or 126, stop:if (thisByte == 126) {  // you could also use if (thisByte == '~') {// This loop loops forever and does nothingwhile (true) {continue;}}// go on to the next characterthisByte++;}
}void setup() {// Serial.begin(9600);// Serial.print("ESP32 Tick Period - ");// Serial.print(portTICK_PERIOD_MS);// Serial.println("ms");if (xTaskCreate(task1,"Blink",1024,NULL,1,NULL) == pdPASS)Serial.println("Task1 Created.");if (xTaskCreate(task2,"ASCII_table",1024,NULL,1,NULL) == pdPASS)Serial.println("Task2 Created.");}void loop() {
}
View Code

3)下载运行代码。观察是否串口打印ASCII表 ,LED闪烁

 

总结:

可以使用 FreeRTOS将模块程序结成为一个更复杂的系统程序。实现积木式开发。

 

http://www.hskmm.com/?act=detail&tid=31805

相关文章:

  • pytorch实训题
  • 数据库基础知识1
  • 近期模拟赛汇总
  • 实用指南:部署Tomcat11.0.11(Kylinv10sp3、Ubuntu2204、Rocky9.3)
  • Hbase的安装与配置
  • 【Azure App Service】App Service是否支持PHP的版本选择呢?
  • OAuth/OpenID Connect 渗透测试完全指南
  • Problem K. 置换环(The ICPC online 2025)思路解析 - tsunchi
  • Go 语言和 Tesseract OCR 识别英文数字验证码
  • Markdown转换为Word:Pandoc模板使用指南 - 实践
  • 2025年10月小程序开发公司最新推荐排行榜,小程序定制开发,电商小程序开发,预订服务小程序开发,活动报名小程序开发!
  • 复习CSharp
  • Rust 和 Tesseract OCR 实现英文数字验证码识别
  • 数据结构-循环队列
  • C语言学习——键盘录入
  • 2025年10月软件开发公司最新推荐,软件定制开发,crm系统定制软件开发,管理系统软件开发,物联网软件开发公司推荐!
  • C语言学习——运算符的学习
  • 第十五篇
  • 数据结构-双向循环链表
  • 数据结构-顺序栈
  • Erlang 的英文数字验证码识别系统设计与实现
  • 使用Django从零开始构建一个个人博客系统 - 实践
  • 2025年磨床厂家TOP企业品牌推荐排行榜,平面磨床,外圆磨床,数控平面磨床,数控外圆磨床,7163平面磨床推荐这十家公司!
  • cifar10
  • [LangChain] 02. 模型接口
  • 摄像头调试
  • C语言学习——字符串数据类型
  • 感知节点@4@ ESP32+arduino+ 第二个程序 LED灯显示
  • WebGL学习及项目实战(第02期:绘制一个点)
  • 2025 年 10 月国内加工中心制造商最新推荐排行榜:涵盖立式、卧式、龙门及多规格型号!