S3196861 Final Code - BBBB
From Physical Programming
// Code used to create a Light Emitting Drink Coaster (LEDc) which reacts to music or sound, pulsing with the sounds.
This code works best with a wall power adapter for usb (such as an apple one), as it was to be used with speakers so i thought the expectation that a power source was there was justified.
I have shown Brandon how it works during SWAT, I had an issue with the grounding of my soldered stuff, which ended up working.
Calibration and Mapping of data was attempted however did not prove succesful in helping to visualize the sounds
int sensorPin = 0; int sensorValue = 0; //int timer =10 ; // delay was not needed in the end however was kept for reading purposes in serial monitor when needed
int LED1 = 11; int LED2 = 10; int LED3 = 9; int LED4 = 8; int LED5 = 7; int LED6 = 6; int LED7 = 5;
void setup() {
pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); pinMode(LED5, OUTPUT); pinMode(LED6, OUTPUT); pinMode(LED7, OUTPUT);
Serial.begin(9600);
}
void loop() {
//digitalWrite(13, HIGH); //testing loop to see each LED is working //digitalWrite(12, HIGH); //digitalWrite(11, HIGH); //digitalWrite(10, HIGH); //digitalWrite(9, HIGH); //digitalWrite(8, HIGH); //digitalWrite(7, HIGH); // digitalWrite(6, HIGH); // digitalWrite(5, HIGH);
sensorValue = analogRead(sensorPin); Serial.println(sensorValue); //delay(timer);
digitalWrite(LED1, HIGH); // the following code was worked out by putting my electret mic next to a subwoofer to gather max and mins of data, this was then used to produce the thresholds at which led's turn on
if (sensorValue>659){ // white led
digitalWrite(LED2, HIGH);
//delay(10);
}
else {
digitalWrite(LED2, LOW);
}
if (sensorValue<350){ //white led
digitalWrite(LED3, HIGH);
//delay(10);
}
else {
digitalWrite(LED3, LOW);
}
if (sensorValue>709){ //blue led
digitalWrite(LED4, HIGH);
//delay(10);
}
else {
digitalWrite(LED4, LOW);
}
if (sensorValue<320){ //blue led
digitalWrite(LED5, HIGH);
//delay(10);
}
else {
digitalWrite(LED5, LOW);
}
if (sensorValue>759){ //green led
digitalWrite(LED6, HIGH);
//delay(10);
}
else {
digitalWrite(LED6, LOW);
}
if (sensorValue<280){ //green led
digitalWrite(LED7, HIGH);
//delay(10);
}
else {
digitalWrite(LED7, LOW); }
}


