WLED/wled00/wled09_button.ino

66 lines
1.6 KiB
Arduino
Raw Permalink Normal View History

/*
* Physical IO
*/
void handleButton()
{
if (buttonEnabled)
{
2018-11-18 00:31:45 +01:00
if (digitalRead(BTNPIN) == LOW && !buttonPressedBefore)
{
buttonPressedTime = millis();
buttonPressedBefore = true;
}
2018-11-18 00:31:45 +01:00
else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore)
{
delay(15); //debounce
2018-11-18 00:31:45 +01:00
if (digitalRead(BTNPIN) == HIGH)
{
if (millis() - buttonPressedTime > 7000) {initAP();}
else if (millis() - buttonPressedTime > 700)
{
if (macroLongPress != 0) {applyMacro(macroLongPress);}
else _setRandomColor(false,true);
}
else {
if (macroButton == 0)
{
toggleOnOff();
colorUpdated(2);
} else {
applyMacro(macroButton);
}
}
buttonPressedBefore = false;
}
}
}
2017-01-27 22:59:01 +01:00
//output
if (auxActive || auxActiveBefore)
{
if (!auxActiveBefore)
{
auxActiveBefore = true;
switch (auxTriggeredState)
{
2018-11-18 00:31:45 +01:00
case 0: pinMode(AUXPIN, INPUT); break;
case 1: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, HIGH); break;
case 2: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, LOW); break;
2017-01-27 22:59:01 +01:00
}
auxStartTime = millis();
}
if ((millis() - auxStartTime > auxTime*1000 && auxTime != 255) || !auxActive)
{
auxActive = false;
auxActiveBefore = false;
switch (auxDefaultState)
{
2018-11-18 00:31:45 +01:00
case 0: pinMode(AUXPIN, INPUT); break;
case 1: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, HIGH); break;
case 2: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, LOW); break;
2017-01-27 22:59:01 +01:00
}
}
}
}