政务网站集约化建设杭州新站整站seo
Arduino示例代码讲解:Pitch follower 跟随
- Pitch follower
- 代码功能
- 代码逐行解释
- 1. 注释部分
- 功能:
- 硬件连接:
- 2. `setup()` 函数
- 3. `loop()` 函数
- 硬件连接
- **扬声器连接**:
- **光敏电阻连接**:
- **Arduino板**:
- 运行结果
- 修改建议
- 视频讲解
Pitch follower
这段代码是一个Arduino示例程序,名为“Pitch follower”,用于根据模拟输入的变化动态调整扬声器发出的音调。
/*Pitch followerPlays a pitch that changes based on a changing analog inputcircuit:* 8-ohm speaker on digital pin 9* photoresistor on analog 0 to 5V* 4.7K resistor on analog 0 to groundcreated 21 Jan 2010modified 31 May 2012by Tom Igoe, with suggestion from Michael FlynnThis 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 rangeSerial.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