标题: arduino声音传感器资料与程序 [打印本页]

作者: 筱豆先生    时间: 2017-11-14 11:38
标题: arduino声音传感器资料与程序
声音传感器资料



arduino源程序如下:
  1. int ledPins[] =  {3,4,5,6,7,8,9,10};
  2. int switchPin = 2;
  3. int soundPin = 0;

  4. boolean showPeak = false;
  5. int peakValue = 0;

  6. void setup()
  7. {
  8.   for(int i = 0;i < 8; i++)
  9.   {
  10.      pinMode(ledPins[i],OUTPUT);
  11.   }
  12.   pinMode(switchPin,INPUT);
  13. }

  14. void loop()
  15. {
  16.   if (digitalRead(switchPin))
  17.   {
  18.     showPeak = !showPeak;
  19.     peakValue = 0;
  20.     delay(200);
  21.   }
  22.   int value = analogRead(soundPin);
  23.   int topLED = map(value,0,400,0,12)-1;
  24.   if(topLED>peakValue)
  25.   {
  26.     peakValue = topLED;
  27.   }
  28.   for(int i = 0;i < 8;i++)
  29.   {
  30.     digitalWrite(ledPins[i],(i <= topLED||(showPeak && i == peakValue)));
  31.   }
  32. }

复制代码

所有资料51hei提供下载:
arduino声音传感器 模拟.rar (211.57 KB, 下载次数: 40)








欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1