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

esp32触发相机

esp32触发相机,测试成功上升沿触发

串口发送命令 up 20000 1 20000 触发

#include <Arduino.h>const int outputPin = 12;  // 输出引脚
String inputCommand = "";  // 串口输入缓冲区// 解析命令参数,例如 "up 10 5" 解析为 delayMicrosecondsTime=10, repeatCount=5// 解析命令参数,例如 "up 10 5" 解析为 delayMicrosecondsTime=10, repeatCount=5
bool parseParameters(String command, int &delayMicrosecondsTime, int &repeatCount) {int firstSpace = command.indexOf(' '); // 查找第一个空格位置if (firstSpace < 0) return false;     // 没有参数int secondSpace = command.indexOf(' ', firstSpace + 1); // 查找第二个空格位置if (secondSpace < 0) return false;                     // 参数不完整// 提取参数并转换为整数String delayMicrosecondsStr = command.substring(firstSpace + 1, secondSpace);String repeatStr = command.substring(secondSpace + 1);delayMicrosecondsTime = delayMicrosecondsStr.toInt();repeatCount = repeatStr.toInt();// 检查参数是否合法return delayMicrosecondsTime > 0 && repeatCount > 0;
}// 解析命令参数,例如 "up 10 5 3" 解析为 delayMicrosecondsTime=10, repeatCount=5, additionalParam=3
bool parseParametersThree(String command, int &delayMicrosecondsTime, int &repeatCount, int &additionalParam) {int firstSpace = command.indexOf(' '); // 查找第一个空格位置if (firstSpace < 0) return false;     // 没有参数int secondSpace = command.indexOf(' ', firstSpace + 1); // 查找第二个空格位置if (secondSpace < 0) return false;                     // 参数不完整int thirdSpace = command.indexOf(' ', secondSpace + 1); // 查找第三个空格位置if (thirdSpace < 0) return false;                      // 参数不完整// 提取参数并转换为整数String delayMicrosecondsStr = command.substring(firstSpace + 1, secondSpace);String repeatStr = command.substring(secondSpace + 1, thirdSpace);String additionalStr = command.substring(thirdSpace + 1);delayMicrosecondsTime = delayMicrosecondsStr.toInt();repeatCount = repeatStr.toInt();additionalParam = additionalStr.toInt();// 检查参数是否合法return delayMicrosecondsTime > 0 && repeatCount > 0 && additionalParam > 0;
}void handleUpCommand(String command) {int delayMicrosecondsTime = 0, repeatCount = 0, additionalParam = 0;if (parseParametersThree(command, delayMicrosecondsTime, repeatCount, additionalParam)) {Serial.println("Triggering UP signal...");for (int i = 0; i < repeatCount; i++) {digitalWrite(outputPin, HIGH); // 输出高电平delayMicroseconds(additionalParam);              // 等待digitalWrite(outputPin, LOW);  // 恢复低电平delayMicroseconds(delayMicrosecondsTime);              // 等待间隔}} else {Serial.println("Invalid parameters for 'up' command");}
}void handleDownCommand(String command) {int delayMicrosecondsTime = 0, repeatCount = 0;if (parseParameters(command, delayMicrosecondsTime, repeatCount)) {Serial.println("Triggering DOWN signal...");for (int i = 0; i < repeatCount; i++) {digitalWrite(outputPin, LOW);  // 输出低电平delayMicroseconds(delayMicrosecondsTime);              // 等待digitalWrite(outputPin, HIGH); // 恢复高电平delayMicroseconds(delayMicrosecondsTime);              // 等待间隔}} else {Serial.println("Invalid parameters for 'down' command");}
}void parseCommand(String command) {command.trim(); // 去掉多余的空格或换行符if (command.startsWith("up")) {handleUpCommand(command);} else if (command.startsWith("down")) {handleDownCommand(command);} else {Serial.println("Invalid command! Use 'up' or 'down'");}
}void setup() {pinMode(outputPin, OUTPUT);   // 设置输出引脚digitalWrite(outputPin, LOW); // 初始化输出为低电平Serial.begin(9600);           // 初始化串口通信
}void loop() {// 检查是否有串口输入while (Serial.available() > 0) {char receivedChar = Serial.read();if (receivedChar == '\n') { // 检测到回车符,执行命令parseCommand(inputCommand);inputCommand = ""; // 清空输入缓冲区} else {inputCommand += receivedChar; // 拼接命令字符}}
}
http://www.lryc.cn/news/492008.html

相关文章:

  • webrtc支持h265
  • macos 14.0 Monoma 修改顶部菜单栏颜色
  • 在 Mac(ARM 架构)上安装 JDK 8 环境
  • Linux高阶——1123—
  • VOLO实战:使用VOLO实现图像分类任务(二)
  • 【kafka02】消息队列与微服务之Kafka部署
  • MySQL系列之数据类型(Numeric)
  • BERT简单理解;双向编码器优势
  • LLamafactory 批量推理与异步 API 调用效率对比实测
  • spf算法、三类LSA、区间防环路机制/规则、虚连接
  • C语言学习 12(指针学习1)
  • TypeError: issubclass() arg 1 must be a class
  • Java面试题、八股文学习之JVM篇
  • 【eNSP】动态路由协议RIP和OSPF
  • 春秋云境 CVE 复现
  • Linux入门攻坚——39、Nginx入门
  • 计算机网络的类型
  • 解决 MySQL 5.7 安装中的常见问题及解决方案
  • VITE+VUE3+TS环境搭建
  • 【设计模式】【创建型模式(Creational Patterns)】之原型模式(Prototype Pattern)
  • 黄仁勋:人形机器人在内,仅有三种机器人有望实现大规模生产
  • 【C语言】宏定义详解
  • LangChain——多向量检索器
  • 《岩石学报》
  • 数据结构 (12)串的存储实现
  • 职场发展陷阱
  • Xcode15(iOS17.4)打包的项目在 iOS12 系统上启动崩溃
  • 极狐GitLab 17.6 正式发布几十项与 DevSecOps 相关的功能【二】
  • PVE相关名词通俗表述方式———多处细节实验(方便理解)
  • Ansible--自动化运维工具