|
通过RespberrypiADC0832来使用麦克风传感器
[复制链接]
3芯积分
microphone.c#include #include #include #include #include #define ADC_CS 0#define ADC_CLK 1#define ADC_DIO 2#define MIC_DO_Pin 3typedef unsigned char uchar;typedef unsigned int uint;uchar get_ADC_Result(void){ uchar i; uchar dat1=0, dat2=0; digitalWrite(ADC_CS, 0); digitalWrite(ADC_CLK,0); digitalWrite(ADC_DIO,1); delayMicroseconds(2); digitalWrite(ADC_CLK,1); delayMicroseconds(2); digitalWrite(ADC_CLK,0); digitalWrite(ADC_DIO,1); delayMicroseconds(2); digitalWrite(ADC_CLK,1); delayMicroseconds(2); digitalWrite(ADC_CLK,0); digitalWrite(ADC_DIO,0); delayMicroseconds(2); digitalWrite(ADC_CLK,1); digitalWrite(ADC_DIO,1); delayMicroseconds(2); digitalWrite(ADC_CLK,0); digitalWrite(ADC_DIO,1); delayMicroseconds(2); for(i=0;i<8;i++) { digitalWrite(ADC_CLK,1); delayMicroseconds(2); digitalWrite(ADC_CLK,0); delayMicroseconds(2); pinMode(ADC_DIO, INPUT); dat1=dat1<<1 | digitalRead(ADC_DIO); } for(i=0;i<8;i++) { dat2 = dat2 | ((uchar)(digitalRead(ADC_DIO))<Python Code#!/usr/bin/env pythonimport RPi.GPIO as GPIOimport ADC0832import timeMIC_DO_PIN = 15def init(): GPIO.setmode(GPIO.BOARD) GPIO.setup(MIC_DO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) ADC0832.setup()def micISR(ev=None): print "voice in..." analogVal = ADC0832.getResult() print 'res = %d' % resdef loop(): GPIO.add_event_detect(MIC_DO_PIN, GPIO.FALLING, callback=micISR) while True: passif __name__ == '__main__': init() try: loop() except KeyboardInterrupt: ADC0832.destroy() print 'The end !'有哪位大哥帮我解释下这两段代码,越详细越好,我刚学啥都不懂!跪谢了 |
|