#include <Arduino.h>
#include <Bounce2.h> // https://github.com/thomasfredericks/Bounce2/archive/refs/heads/master.zip
Bounce2::Button button = Bounce2::Button();
const int buttonPin = 4;
const int ledPin = 10;
const int blinktime = 60; // Seconds
const int blinkPerSecond = 8;
const int blinkPerTime = blinktime * blinkPerSecond;
const int blinkInteval = (blinktime * 1000UL) / blinkPerTime;
unsigned long prevMicros = 0;
unsigned long stepMicros = 0;
bool startBlink = false;
bool ledState = false;
void setup()
{
pinMode(ledPin, OUTPUT);
button.attach(buttonPin, INPUT_PULLUP);
button.interval(5); // interval im ms
button.setPressedState(LOW);
}
void loop()
{
if (startBlink == false)
{
button.update();
if (button.pressed())
{
startBlink = true;
prevMicros = micros();
}
}
if (((micros() - prevMicros) <= (blinktime * 1000UL * 1000UL)) && (startBlink == true))
{
if ((micros() - stepMicros) >= ((blinkInteval * 1000UL) / 2))
{
ledState = !ledState;
digitalWrite(ledPin, ledState);
stepMicros = micros();
}
}
else
{
digitalWrite(ledPin, LOW);
startBlink = false;
}
}
ERC Warnings
flop1:CLK: Clock driven by combinatorial logic