Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#define sample 300
int inPin = 5;
int val;
int speaker = 13;
int array1[sample];
unsigned long averaging;
void setup()
{
Serial.begin(9600);
}
void loop()
{
for(int i = 0; i < sample; i++)
{
array1[i] = analogRead(inPin);
averaging += array1[i];
}
val = averaging / sample;
val = constrain(val, 0, 100);
val = map(val, 0, 100, 0, 200);
if(val < 6)
{
val = 0;
}
analogWrite(speaker,val);
averaging = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment