## 課程學習記錄 ```java = const int SOUND_SENSOR_PIN = A0; // 模拟量输出连接到A0 const int LED_PIN = 13; // LED连接到数字引脚13 void setup() { // 初始化串口通信 Serial.begin(9600); // 设置LED引脚为输出模式 pinMode(LED_PIN, OUTPUT); } void loop() { // 读取模拟量输出 int soundValue = analogRead(SOUND_SENSOR_PIN); Serial.print("Sound Value: "); Serial.println(soundValue); // 根据声音大小判断是否超过阈值 if (soundValue > 500) { // 声音强度大于阈值,点亮LED digitalWrite(LED_PIN, HIGH); Serial.println("LED ON"); } else { // 声音强度低于阈值,关闭LED digitalWrite(LED_PIN, LOW); Serial.println("LED OFF"); } delay(1000); // 延迟1秒 } ``` ```java = const int SOUND_SENSOR_PIN = A0; // 模拟量输出连接到A0 const int LED_PIN = 13; // LED连接到数字引脚13 void setup() { // 初始化串口通信 Serial.begin(9600); // 设置LED引脚为输出模式 pinMode(LED_PIN, OUTPUT); } void loop() { // 读取模拟量输出 int soundValue = analogRead(SOUND_SENSOR_PIN); Serial.print("Sound Value: "); Serial.println(soundValue); // 根据声音大小判断是否超过阈值 if (soundValue > 500) { // 声音强度大于阈值,点亮LED digitalWrite(LED_PIN, HIGH); Serial.println("LED ON"); } else { // 声音强度低于阈值,关闭LED digitalWrite(LED_PIN, LOW); Serial.println("LED OFF"); } delay(1000); // 延迟1秒 } ``` [⬇️程式碼來源](https://home.gamer.com.tw/creationDetail.php?sn=4768572&fbclid=IwAR0qKCWWUISAtQrdHUtxaHUFJ96wgA2DBxc_MT9VrX5MK7A8iwLElme8jEM) ```javascript = #include "Arduino.h" #include "SoftwareSerial.h" #include "DFRobotDFPlayerMini.h" SoftwareSerial mySoftwareSerial(11, 10); // RX, TX DFRobotDFPlayerMini myDFPlayer; void setup() { mySoftwareSerial.begin(9600); Serial.begin(115200); Serial.println(); Serial.println(F("DFRobot DFPlayer Mini Demo")); Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3. Serial.println(F("Unable to begin:")); Serial.println(F("1.Please recheck the connection!")); Serial.println(F("2.Please insert the SD card!")); while(true){ delay(0); // Code to compatible with ESP8266 watch dog. } } Serial.println(F("DFPlayer Mini online.")); myDFPlayer.volume(10); //Set volume value. From 0 to 30 myDFPlayer.play(1); //Play the first mp3 } void loop() { } ``` ## 專案進度 喜獲一些新道具! [Sound_Sensor](https://www.waveshare.net/wiki/Sound_Sensor)