/*
Heartbeat LED
dimms up and down.
Can be used for a "heartbeat" LED
you must connect the LED to a PWM enabled PIN
by noiasca
2022-01-17 2916/224
2022-01-16 2894/225 genericPin
2021-12-0 2884/224 basePin
*/
// 5 August 2023: Changes to make it work in Wokwi:
// All files of the library uploaded as local files.
// No sub-folders.
// Changed includes to local inclused with "
// Removed include from bottom of Noiasca_led.h
//
#include "Noiasca_led.h" // download library from http://werner.rothschopf.net/microcontroller/202202_tools_led_en.htm
#include "Noiasca_discrete.h" // use the discrete pins on the Arduino/Microcontroller
#include "Noiasca_button.h" // some tools to read buttons
HeartbeatPin heartbeatLed {3}; // UNO PWM pins 3, 5, 6, 9, 10, 11 (on any other pin the LED will just blink)
Button button[] {A0, A1, A2}; // button connects pin with GND, "active LOW"
void setup() {
Serial.begin(115200);
heartbeatLed.begin(); // you have to call the .begin() method for the LED pair
heartbeatLed.on(); // you can switch the LED on
heartbeatLed.setInterval(10); // you can modify the delay time for the pulsing. Default value is 50.
heartbeatLed.setMinBrightness(50); // you can limit the mininum brightness. Default value is 0
//heartbeatLed.setMaxBrightness(240);// you can limit the maximum brightness. Default value is 255. Highest value on Arduino is 255.
for (auto &obj : button) {
obj.begin(); // you have to call the .begin() method for each button
}
}
void loop() {
// read the buttons
if (button[0].wasPressed()) {
Serial.println(F("button 0 was pressed, switch ON LED"));
heartbeatLed.on(); // switch on LED
}
if (button[1].wasPressed()) {
Serial.println(F("button 1 was pressed, switch OFF LED"));
heartbeatLed.off(); // switch off LED
}
if (button[2].wasPressed()) {
Serial.println(F("button 2 was pressed, toogle LED (change from ON to OFF or vice versa)"));
heartbeatLed.toggle(); // if button was pressed, toggle (change state) of LED
}
heartbeatLed.update(); // you have to call update() for the LED
}