int threshold=50;
int toneDuration=10;
int speakerPin=8;
int sensorValue1=0;
int led1=3;
int toneFrequency1=262;
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many p
unsigned long previousMillis = 0;
const long interval = 30;
void setup() {
pinMode(led1,OUTPUT);
void loop() {
// put your main code here, to run repeatedly:
sensorValue1=analogRead(A0);
if (sensorValue1>threshold){
tone(speakerPin,toneFrequency1,toneDuration);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
brightness = brightness + fadeAmount;
analogWrite(led1, brightness);
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
}
}
int toneDuration=10;
int speakerPin=8;
int sensorValue1=0;
int led1=3;
int toneFrequency1=262;
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many p
unsigned long previousMillis = 0;
const long interval = 30;
void setup() {
pinMode(led1,OUTPUT);
void loop() {
// put your main code here, to run repeatedly:
sensorValue1=analogRead(A0);
if (sensorValue1>threshold){
tone(speakerPin,toneFrequency1,toneDuration);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
brightness = brightness + fadeAmount;
analogWrite(led1, brightness);
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
}
}