int gnd = 8; int red = 9; int green = 10; int blue = 11; int redIntensity = 0; int greenIntensity = 0; int blueIntensity = 0; int micPin = A0; // pin that the mic is attached to int gndPin = A1; int powerPin = A2; int micValue1 = 0; int micValue2 = 0; // the Microphone value int loudness = 0; int absLoudness = 0; void setup() { // put your setup code here, to run once: pinMode(gnd, OUTPUT); pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); digitalWrite(gnd,LOW); pinMode(powerPin, OUTPUT); pinMode(gndPin, OUTPUT); pinMode(micPin, INPUT); digitalWrite(gndPin,LOW); delay(500); digitalWrite(powerPin,HIGH); } void loop() { micValue1 = analogRead(micPin); // read pin value delay(1); micValue2 = analogRead(micPin); loudness = micValue2-micValue1; absLoudness = abs(loudness); if (absLoudness < 2){ redIntensity = 0; greenIntensity = 0; blueIntensity = 0; } if (absLoudness ==2){ redIntensity = random(0,10); greenIntensity = random(0,10); blueIntensity = random(0,10); } if (absLoudness ==3){ redIntensity = random(10,30); greenIntensity = random(10,30); blueIntensity = random(10,30); } if (absLoudness ==4){ redIntensity = random(20,45); greenIntensity = random(20,45); blueIntensity = random(20,45); } if (absLoudness > 4){ redIntensity = random(131,255); greenIntensity = random(131,255); blueIntensity = random(131,255); } analogWrite(red,redIntensity); analogWrite(green,greenIntensity); analogWrite(blue,blueIntensity); delay(200); }