#include <Tone32.h>
#include <pitches.h>
#define IR_Sensor 18
#define BUZZER_PIN 19
#define BUZZER_CHANNEL 0
int Counter;
int IR;
int frequency;
// the setup function runs once when you press reset or power the board
void setup()
{
Serial.begin(115200);
Serial.println("Setup start");
pinMode(IR_Sensor, INPUT);
Serial.println("Setup end");
}
// the loop function runs over and over again until power down or reset
void loop()
{
if (Counter == 0)
{
IR = digitalRead(IR_Sensor);
if (IR = HIGH)
{
Counter++;
Serial.println(Counter);
delay(1000);
}
}
if (Counter >= 1);
{
Counter++;
delay(1000);
}
if (Counter >= 900)
{
Serial.println(Counter);
Counter = 0;
delay(500);
}
Serial.println(Counter);
Buzzz();
Serial.println(frequency);
}
void Buzzz()
{
if (Counter == 300 && Counter <= 600)
{
frequency = 4000;
}
if (Counter == 600 && Counter <= 900)
{
frequency = 8000;
}
if (Counter <= 300)
{
Serial.println("Buzz");
tone(BUZZER_PIN, frequency, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
delay(500);
tone(BUZZER_PIN, frequency, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
delay(500);
}
}