void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
}
String soundlevel(int a){
String s;
if(a<200) {
s= "LOW";
}
if(a<350 && a>200) {
s= "MEDUIM";
}
if(a>350 && a<500) {
s= "HIGH";
}
if(a>500) {
s= "VERY_HIGH";
}
return s;
}
String lightlevel(int a){
String s;
if(a<70) {
s= "Low";
}
if(a>70 && a<200) {
s= "Meduim";
}
if(a>200) {
s= "High";
}
return s;
}
void outsound(String a){
if(a=="LOW"){
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
}
if(a=="MEDUIM"){
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
}
if(a=="HIGH"){
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
}
if(a=="VERY_HIGH"){
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
}
}
void outlight(String a){
if(a=="Low"){
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}
if(a=="Meduim"){
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
}
if(a=="High"){
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
}
}
void loop(){
String r;
int a = analogRead(A1);
int b = analogRead(A2);
a=(a*1.2);//sound amplification
outsound(soundlevel(a));
outlight(lightlevel(b));
}
Comments
Please log in or sign up to comment.