#include <TimerOne.h>
const int pinLED = 9;
bool ledState = LOW;
volatile bool buttonState = false;
volatile unsigned long blinkCount = 0;
void setup()
{
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, ClickButton, FALLING);
Timer1.initialize(200000);
Timer1.attachInterrupt(FuncSOS);
Timer1.stop();
}
void loop()
{
}
void ClickButton()
{
if (buttonState == false)
{
buttonState = !buttonState;
Timer1.start();
}
}
void FuncSOS()
{
if (blinkCount > 2 && blinkCount < 6)
{
Timer1.setPeriod(600000);
}
else
{
Timer1.setPeriod(200000);
}
if (ledState == LOW)
{
ledState = HIGH;
blinkCount++; //количество миганий
}
else
{
ledState = LOW;
if (blinkCount == 9)
{
buttonState = !buttonState;
blinkCount = 0;
Timer1.stop();
}
}
digitalWrite(pinLED, ledState);
}