Oh I totally overlooked it. But it is still not working. I must be something wrong!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int calibrationTime = 30;
const int sensorPin = 2;
const int speakerPin = 9;
const int pitchPin = 0;
const int resetPin = 7;
int prevState = LOW;
int currState;
bool screaming = false;
int resetState = digitalRead(resetPin);
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
pinMode(resetPin, INPUT);
}
void Scream()
{
int frequentie = analogRead(pitchPin);
int frequency = map(frequentie, 0, 1023, 100,5000);
int duration = 250;
tone(speakerPin, frequency, duration);
delay(100);
lcd.init();
lcd.backlight();
lcd.print("ALARM");
}
void loop()
{
currState = digitalRead(sensorPin);
if(currState != prevState)
{
if(currState == HIGH)
{
screaming = true;
}
}
prevState = currState;
int resetState = digitalRead(resetPin);
if(resetState == HIGH) // Or LOW, if you wired the switch that way
{
screaming = false;
lcd.init();
lcd.backlight();
lcd.print("...");
}
if(screaming)
{
Scream();
}
}