#ifdef __AVR__
#include <avr/power.h>
#endif
#include <jled.h>
#include "avdweb_Switch.h"
#define LEDPIN 4
#define BUTTONPIN 0
#define ONBOARDLED 1
uint8_t s = 0;
bool state = false;
const long onInterval = 6UL * 60 * 60 * 1000; // 6 hours in milliseconds
//const long onInterval = 1UL * 60 * 1000 ; // 1 minute in mills
unsigned long startMillis;
unsigned long currentMillis;
auto led = JLed(LEDPIN);
Switch button = Switch(BUTTONPIN, INPUT_PULLUP, LOW, 50);
// the setup routine runs once when you press reset:
void setup() {
pinMode(LEDPIN, OUTPUT);
startMillis = millis();
button.setPushedCallback(&buttonPressed);
button.setReleasedCallback(&buttonReleased);
}
// the loop routine runs over and over again forever:
void loop() {
button.poll();
maybeTurnOff();
if (!state) {
switch (s) {
case 1:
led.On().MaxBrightness(225);
break;
case 2:
led.Breathe(3000).MinBrightness(10).Forever().DelayAfter(500); //fast fade
break;
case 3:
led.Breathe(15000).MinBrightness(10).Forever(); // slow fade
break;
default:
led.On().MaxBrightness(225);
break;
}
state = true;
}
led.Update();
}
void buttonPressed() {
digitalWrite(ONBOARDLED, HIGH);
s++;
if (s > 3) {
s = 1;
}
}
void buttonReleased() {
digitalWrite(ONBOARDLED, LOW);
led.Reset();
startMillis = currentMillis;
state = false;
}
void maybeTurnOff() {
currentMillis = millis();
if (currentMillis - startMillis >= onInterval) {
led.Stop(JLed::eStopMode::FULL_OFF);
startMillis = currentMillis;
}
}
Comments
0 B
|👍
/👎