Created
April 9, 2015 16:31
-
-
Save le-mason/20f09c6406caa5b85755 to your computer and use it in GitHub Desktop.
This file contains 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
#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