树莓派练习程序(声音检测)

原文链接: http://www.cnblogs.com/tiandsp/p/8371629.html

声音检测模块如下:

树莓派练习程序(声音检测)_第1张图片

树莓派的引脚如下图:

树莓派练习程序(声音检测)_第2张图片

我们将Vcc引脚连接物理接口1,GND引脚连接物理接口39,DO引脚连接物理接口40。

实物连接如下图:

树莓派练习程序(声音检测)_第3张图片

编程使用WiringPi库,使用wpi引脚编码方式控制GPIO。

代码如下:

#include 
#include 
#include 

#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;
}

输出结果:

树莓派练习程序(声音检测)_第4张图片

转载于:https://www.cnblogs.com/tiandsp/p/8371629.html

你可能感兴趣的:(树莓派练习程序(声音检测))