How can I add a servo that keeps turning while the anolog value from the sound s
ID: 3769632 • Letter: H
Question
How can I add a servo that keeps turning while the anolog value from the sound sensor has exceeded 300, as is already the case for this simple code to make an lcd say "be quiet" when the sound sensor indicates the volume is too high. Please modify the code and post, this is for the arduino. Thank you.
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
void setup() {
lcd.begin(16,2);
Serial.begin(9600);
}
void loop()
{
if(analogRead(0)>300)// sound input value @ which lcd changes to be quiet!
{
lcd.clear();//blank lcd
lcd.setRGB(255,0,0);//red backlight
lcd.print("Be Quiet!!");//msg to display
delay(500);
}
else
{
lcd.clear();//blank lcd
lcd.setRGB(255,255,255);// white backlight
lcd.print("Thanks Everyone");//msg to display
delay(500);
}
}
Explanation / Answer
}
#include <Servo.h> int flexpin=A0; int flexpin1=A1; int pos=90; int pos1=90; Servo myservo, myservo1; int flex[20]; int flex1[20]; int flexsum=0; int flexsum1=0; void setup() { myservo.attach(7); myservo1.attach(8); Serial.begin(9600); } void loop() { for(int x=0; x<20; x++) { flex[x]=analogRead(flexpin); flex1[x]=analogRead(flexpin1); flexsum=flexsum+analogRead(flexpin); flexsum1=flexsum1+analogRead(flexpin1); delayMicroseconds(14); } flexsum=flexsum/20; flexsum1=flexsum1/20; if(Serial.available()) { Serial.println(flexsum); Serial.println(flexsum1); delay(100); } pos=map(flexsum,870,800,0,180); pos1=map(flexsum1,870,800,0,180); myservo.write(pos); myservo1.write(pos1); delay(200);}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.