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

Arduino示例代码讲解:Pitch follower 跟随

Arduino示例代码讲解:Pitch follower 跟随

  • Pitch follower
      • 代码功能
      • 代码逐行解释
        • 1. 注释部分
        • 功能:
        • 硬件连接:
        • 2. `setup()` 函数
        • 3. `loop()` 函数
      • 硬件连接
        • **扬声器连接**:
        • **光敏电阻连接**:
        • **Arduino板**:
      • 运行结果
      • 修改建议
    • 视频讲解

Pitch follower

这段代码是一个Arduino示例程序,名为“Pitch follower”,用于根据模拟输入的变化动态调整扬声器发出的音调。

/*
  Pitch follower

 Plays a pitch that changes based on a changing analog input

 circuit:
 * 8-ohm speaker on digital pin 9
 * photoresistor on analog 0 to 5V
 * 4.7K resistor on analog 0 to ground

 created 21 Jan 2010
 modified 31 May 2012
 by Tom Igoe, with suggestion from Michael Flynn

This example code is in the public domain.

 http://arduino.cc/en/Tutorial/Tone2

 */


void setup() {
   
  // initialize serial communications (for debugging only):
  Serial.begin(9600);
}

void loop() {
   
  // read the sensor:
  int sensorReading = analogRead(A0);
  // print the sensor reading so you know its range
  Serial.println(sensorReading);
  // map the analog input range (in this case, 400 - 1000 from the photoresistor)
  // to the output pitch range (120 - 1500Hz)
  // change the minimum 

相关文章:

  • 舞狮表演(dp)
  • 基于32单片机的无人机直流电机闭环调速系统设计
  • xpath轴
  • git 子模块的使用
  • EMQX安装与配置
  • java项目之基于ssm的疫苗预约系统(源码+文档)
  • 基于分类算法的学习失败预警(上)
  • 力扣热题100(方便自己复习,自用)
  • 利用ffmpeg库实现音频Opus编解码
  • 车载以太网网络测试-18【传输层-DOIP协议-1】
  • PyTorch模型转ONNX例子
  • 深入探究 JVM 堆的垃圾回收机制(一)— 判活
  • python3 -m http.sever 8080加载不了解决办法
  • 6个常见的Python设计模式及应用场景
  • Python实战:开发经典猜拳游戏(石头剪刀布)
  • MySQL事务全解析:从概念到实战
  • 【CXX-Qt】2.1.1 为 WebAssembly 构建
  • 汽车免拆诊断案例 | 2024 款路虎发现运动版车无法正常识别智能钥匙
  • Java EE 进阶:MyBatis
  • 【NLP】 11. 神经网络,线性模型,非线性模型,激活函数,感知器优化,正则化学习方法
  • 董军同德国国防部长举行会谈
  • 新闻1+1丨城市,如何对青年更友好?
  • 昆明警方重拳打击经济领域违法犯罪:去年抓获905名嫌犯
  • 陕西旱情实探:大型灌区农业供水有保障,大旱之年无旱象
  • 第十二届警博会在京开幕:12个国家和地区835家企业参展
  • 巴方:印度上周导弹袭击造成至少40名平民死亡