int audiosense = A5;
int servopin = A4;
int pulse = 1000;
int value;
int button = D2;
Servo servo;
int sPos = 0;
void setup() {
pinMode(audiosense,INPUT);
pinMode(servopin,OUTPUT);
pinMode(button,INPUT_PULLUP);
Particle.variable("soundvalue",value);
servo.attach( servopin );
}
void loop() {
int state = digitalRead(button);
if (state == HIGH){
value = soundDetect();
if (value > 3000)
{
if( sPos == 0 )
servo.write( 180 );
sPos = 180;
delay( 1000 );
}else{
if( sPos == 180 )
servo.write( 0 );
sPos = 0;
}
}
}
int soundDetect() { //when soundDetect is call this is what is run
return analogRead(audiosense); //this takes a reading from the audioSensor pin
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .