Skip to content

Instantly share code, notes, and snippets.

@le-mason
Created April 9, 2015 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le-mason/20f09c6406caa5b85755 to your computer and use it in GitHub Desktop.
Save le-mason/20f09c6406caa5b85755 to your computer and use it in GitHub Desktop.
#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