|
|
| 第24行: |
第24行: |
| | === 引脚说明 === | | === 引脚说明 === |
| | [[Image:LEGO乐高电机-PINOUT.png |LEGO-乐高电机-PINOUT]] | | [[Image:LEGO乐高电机-PINOUT.png |LEGO-乐高电机-PINOUT]] |
| − |
| |
| − |
| |
| − | === 应用示例 ===
| |
| − | <br>
| |
| − | 示例需要硬件:
| |
| − | * Arduino UNO
| |
| − | * Arduino UNO 专用扩展板
| |
| − | * 乐高电机
| |
| − | * 食人鱼模块
| |
| − | * 线材
| |
| − |
| |
| − | ==== 电路连接示意图 ====
| |
| − |
| |
| − | '''食人鱼模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC、D5引脚。
| |
| − | '''乐高电机'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC、A3引脚。
| |
| − |
| |
| − | [[Image:LEGO-乐高电机-连接示意图.jpg|600px|乐高电机连接示意图]]
| |
| − |
| |
| − | {| border="0" cellpadding="5" width="100%"
| |
| − | |width="33%" valign="top" align="left"|
| |
| − |
| |
| − | ==== '''Arduino IDE示例代码''' ====
| |
| − |
| |
| − | '''复制代码至Arduino IDE中编译上传'''
| |
| − | <source lang="c">
| |
| − | int sensorPin = A3; // select the input pin for the sound sensor
| |
| − | int ledPin = 5; // select the pin for the LED
| |
| − |
| |
| − | void setup() {
| |
| − | pinMode(ledPin, OUTPUT);
| |
| − | Serial.begin(9600);
| |
| − | }
| |
| − |
| |
| − | void loop() {
| |
| − | int sensorValue = analogRead(sensorPin); // read the value from the sensor
| |
| − | Serial.println(sensorValue);
| |
| − | // if the sound sensor’s value is greater than 200, the led will be on for 2 seconds.
| |
| − | // Otherwise, the led will be turned off
| |
| − | if (sensorValue > 200) {
| |
| − | digitalWrite(ledPin, HIGH); // turn the ledPin on
| |
| − | delay(2000);
| |
| − | } else {
| |
| − | digitalWrite(ledPin, LOW); // turn the ledPin off
| |
| − | }
| |
| − | }
| |
| − | </source>
| |
| − |
| |
| − | |width="33%" valign="top" align="left"|
| |
| − |
| |
| − | ==== '''Mixly示例代码''' ====
| |
| − |
| |
| − | '''[http://mixly.org Mixly]V1.1.5、[https://gitee.com/finalvalue/yfrobot-lego-lib-for-mixly1.0 YFlego库]V0.1.1 '''
| |
| − |
| |
| − | [[Image:LEGO-乐高电机-Mixly-SoundSensor.png|500px|LEGO-乐高电机-Mixly示例]]
| |
| − |
| |
| − |
| |
| − | |width="33%" valign="top" align="left"|
| |
| − |
| |
| − | ==== '''Mind+示例代码''' ====
| |
| − |
| |
| − | '''[http://mindplus.cc/ Mind+] 1.7 '''
| |
| − |
| |
| − | [[Image:LEGO-乐高电机-Mind-SoundSensor.png|430px|LEGO-乐高电机-Mind+示例]]
| |
| − |
| |
| − | |}
| |
| − |
| |
| − | ===='''程序运行结果'''====
| |
| − |
| |
| − | 当传感器检测到环境声音强度大于设定值(此处为200,可改其他值试试效果,范围0~1023)时,食人鱼模块点亮2s;否则食人鱼模块熄灭。生活中常见的楼道灯,就是利用这个原理实现的。
| |
| − |
| |
| − |
| |
| − |
| |
| − |
| |
| − | ===参考资料===
| |
| − | <br>
| |
| − | * \
| |
| | | | |
| | | | |