Created
March 11, 2020 17:46
-
-
Save Tchoukoualeu/7476a60717d02d7e3a668ee4459f4c65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
//here is an input for sound sensor | |
pinMode(A0, INPUT); | |
//here we are setting up all pins as an outputs for LEDs | |
for(int z = 0; z < 10; z++){ | |
pinMode(z, OUTPUT); | |
} | |
} | |
void loop() { | |
//here we are storing the volume value | |
int volume = analogRead(A0); | |
//max value for analog read is 1023 but it must be very very loud to reach this value | |
//so I lower it down in map function to 700 | |
//mapping volume value to make it easier to turn LEDs on | |
volume = map(volume, 0, 700, 0, 10); | |
//for loop to turn on or off all LEDs | |
//thanks to this loop code for this project is very short | |
//we are going through all pins where we have LEDs and checking if the volume is | |
//bigger then pin number (that's why we are maping the volume) | |
for(int a = 0; a < 10; a++){ | |
if(volume >= a){ | |
//if it is bigger we can turn on the LED | |
digitalWrite(a, HIGH); | |
}else{ | |
//if it is smaller we can turn the LED off | |
digitalWrite(a, LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment