#include <Button_SL.hpp> // https://github.com/DoImant/Button_SL
using MillisType = decltype(millis());
namespace gc {
constexpr uint8_t ButtonPin {4};
constexpr uint8_t RedLedPin {5};
constexpr uint8_t GreenLedPin {6};
constexpr uint8_t BuzzerPin {12};
constexpr MillisType ShortDelay_ms {5000};
constexpr MillisType LongDelay_ms {10000};
}
Btn::ButtonSL Button {gc::ButtonPin};
void lightLedWithDelay(uint8_t Pin, MillisType Time_ms) {
digitalWrite(Pin, HIGH);
delay(Time_ms);
digitalWrite(Pin, LOW);
}
void setup() {
Button.begin();
}
void loop() {
if(Button.tick() != Btn::ButtonState::notPressed) {
lightLedWithDelay(gc::RedLedPin ,gc::ShortDelay_ms);
tone(gc::BuzzerPin,1000,200); // Pin, Hz, Duration
lightLedWithDelay(gc::GreenLedPin ,gc::LongDelay_ms);
tone(gc::BuzzerPin,2000,200);
lightLedWithDelay(gc::RedLedPin ,gc::ShortDelay_ms);
}
}
Click Button