#include "OneButton.h"
// Setup a new OneButton on pin A1.
OneButton button(A1);
bool boolSky;
bool switchSky;
int fadeSky;
int addSkyLights = 8;
// setup code here, to run once:
void setup() {
Serial.begin(9600);
fadeSky = 12000;
// enable the standard led on pin 13.
pinMode(addSkyLights, OUTPUT); // sets the digital pin as output
// link the doubleclick function to be called on a doubleclick event.
button.attachClick(oneclickSky);
button.attachDuringLongPress(duringLongPressSky);
button.attachLongPressStop(longPressStopSky);
} // setup
// main code here, to run repeatedly:
void loop() {
// keep watching the push button:
button.tick();
// You can implement other code in here or just wait a while
} // loop
// this function will be called when the button was pressed 2 times in a short timeframe.
void longPressStopSky()
{
Serial.print(fadeSky);
boolSky = !boolSky;
Serial.print("Bool:");
Serial.println(boolSky);
}
void duringLongPressSky()
{
//Serial.println("Counter"+counter);
//Serial.println(fadeValue);
//static int fadeValue = 0
if(boolSky == 0 && fadeSky < 25500)
{
analogWrite(addSkyLights, fadeSky/100);
fadeSky += 1;
}
if(boolSky == 1 && fadeSky > 0)
{
analogWrite(addSkyLights, fadeSky/100);
fadeSky -= 1;
}
}
void oneclickSky()
{
if(switchSky == 0)
{
analogWrite(addSkyLights, fadeSky/100);
digitalWrite(LED_BUILTIN,HIGH);
}
else
{
analogWrite(addSkyLights, 0);
digitalWrite(LED_BUILTIN,LOW);
}
Serial.print("Light switched!");
switchSky = !switchSky;
Serial.println(switchSky);
}