MSP430带有RGB LED灯的声音传感器

时间:2018-07-26 16:26:58

标签: audio rgb sensor led msp430

因此,我使用带有MSP430芯片的声音传感器芯片进行了此项目,并且当声音通过时必须使RGB亮起。

enter image description here

#include <msp430.h>
#include <Wire.h>

int soundsensor = 3;
int RGB = 19;
int RED_PIN = 12;
int GREEN_PIN = 13;
int BLUE_PIN = 14;
int counter = 0;

void setup() 
{ 
  Serial.begin(9600);
  Serial.println("Begin Testing");
  pinMode(soundsensor,INPUT);
  pinMode(RGB,INPUT);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);}

void loop()
{

int sensorValue = analogRead(soundsensor);
Serial.println(sensorValue);
counter = sensorValue / 100;
Serial.println(counter);

delay(250); 


if (counter >= 0 && counter <= 2) //
{
  Serial.println("LOUD");
  digitalWrite(RED_PIN,HIGH);
  digitalWrite(GREEN_PIN,LOW);
  digitalWrite(BLUE_PIN,HIGH);

 } 



 if (counter >= 3  && counter <= 4) //
{
  Serial.println("LOUD");
  digitalWrite(RED_PIN,HIGH);
  digitalWrite(GREEN_PIN,HIGH);
  digitalWrite(BLUE_PIN,LOW);

 }

 if (counter >= 5  && counter <= 7) //
{
  Serial.println("LOUD");
  digitalWrite(RED_PIN,LOW);
  digitalWrite(GREEN_PIN,HIGH);
  digitalWrite(BLUE_PIN,HIGH);

 }

 if (counter >= 8  && counter <= 9) //
{
  Serial.println("LOUD");
  digitalWrite(RED_PIN,LOW);
  digitalWrite(GREEN_PIN,HIGH);
  digitalWrite(BLUE_PIN,LOW);

 }

因此,当代码运行时,它将声音读为值,然后我将其除以100,以得到阈值之间的数字并更改为不同的颜色。

问题是,当我运行程序时,我的显示唯一值是500(在100%后为5),并且除非我将音乐放在声音传感器上并且颜色改变,否则它不会改变。我想知道为什么尽管周围没有噪音,但是基数还是500?因为除非我放大声的视频游戏音乐来演示如何使其达到0-2之间的阈值,否则它只会更改为2种颜色。谢谢

0 个答案:

没有答案