树莓派练习程序(声音检测)
2018-01-28 16:56
225 查看
声音检测模块如下:
![](https://images2017.cnblogs.com/blog/340413/201801/340413-20180128165338115-617920400.png)
树莓派的引脚如下图:
![](https://images2017.cnblogs.com/blog/340413/201801/340413-20180128121412897-392760621.png)
我们将Vcc引脚连接物理接口1,GND引脚连接物理接口39,DO引脚连接物理接口40。
实物连接如下图:
![](https://images2017.cnblogs.com/blog/340413/201801/340413-20180128165415147-1058024173.jpg)
编程使用WiringPi库,使用wpi引脚编码方式控制GPIO。
代码如下:
输出结果:
![](https://images2017.cnblogs.com/blog/340413/201801/340413-20180128165338115-617920400.png)
树莓派的引脚如下图:
![](https://images2017.cnblogs.com/blog/340413/201801/340413-20180128121412897-392760621.png)
我们将Vcc引脚连接物理接口1,GND引脚连接物理接口39,DO引脚连接物理接口40。
实物连接如下图:
![](https://images2017.cnblogs.com/blog/340413/201801/340413-20180128165415147-1058024173.jpg)
编程使用WiringPi库,使用wpi引脚编码方式控制GPIO。
代码如下:
#include <wiringPi.h> #include <stdio.h> #include <sys/time.h> #define SHENGYIN 29 int main(void) { if (wiringPiSetup() == -1) { printf("setup wiringPi failed !"); return 1; } pinMode(SHENGYIN, INPUT); while (1) { if (digitalRead(SHENGYIN) == 0) { printf("no sound\n"); delay(333); } else { printf("sound\n"); delay(333); } } return 0; }
输出结果:
![](https://images2017.cnblogs.com/blog/340413/201801/340413-20180128165525162-698947743.png)
相关文章推荐
- 树莓派练习程序(土壤湿度检测)
- 树莓派练习程序(雨水检测)
- 树莓派练习程序(火焰检测)
- 树莓派练习程序(寻迹模块)
- matlab练习程序(霍夫变换检测直线斜率)
- 树莓派练习程序(光敏电阻)
- 树莓派练习程序(避障模块)
- 树莓派练习程序(超声波测距)
- 树莓派练习程序(蜂鸣器)
- matlab练习程序(Marr-Hildreth边缘检测)
- matlab练习程序(SUSAN检测)
- matlab练习程序(SUSAN检测)
- 树莓派练习程序(温度湿度测量)
- matlab练习程序(Canny边缘检测)
- matlab练习程序(并行计算)
- linux恶意程序检测和APT检测
- Learning OpenCV: 一个简单的人眼检测程序
- 禁止程序检测vmware
- 第一个Win32程序(自动检测光驱)
- opencv实践程序4——canny实现摄像头的边缘检测,高斯背景建模