We human spend one-third of life sleeping, preparing for an energetic day. However, during our period of sleeping, there is usually some noise from the surrounding,the honk from vehicles on the road, laughter and screaming by your neighbors. They are so common in our daliy life that we almost ignore them and accept them as part of life. To be honest , the ignorance itself isn't good at all, it weaken our spirit day by day since we didn't get enough rest everyday.
To deal with this thorny situation, we decide to make an reacting system which can react instantly according to the input db (unit of noise) to alert you when the noise is large enough to lessen your quality of sleep, for the further plan, we want to design an machanic to block or lower the noise automatically .
const int buzzer = 8; | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin LED_BUILTIN as an output. | |
pinMode(LED_BUILTIN, OUTPUT); | |
pinMode(buzzer,OUTPUT); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
char a[4]; | |
char b[3]={'0','4','0'}; | |
scanf("%c%c%c",&a[0],&a[1],&a[2]); | |
for(int j=0;j<3;j++){ | |
if(a[j]>b[j]){ | |
for(int i=0;i<30;i++){ | |
digitalWrite(LED_BUILTIN, HIGH); | |
tone(buzzer,1000); | |
delay(100); // wait for a second | |
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW | |
tone(buzzer,500); | |
delay(100); | |
} | |
noTone(buzzer); | |
break; | |
} | |
else if(a[j]<b[j]) break; | |
} | |
} |
SpaceApps is a NASA incubator innovation program.