123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- void handleButtonLogic() {
- bool modePressed = (digitalRead(BUTTON_MODE) == LOW);
- bool addPressed = (digitalRead(BUTTON_ADD) == LOW);
- bool colorPressed = (digitalRead(BUTTON_COLOR) == LOW);
- bool minusPressed = (digitalRead(BUTTON_MINUS) == LOW);
- if (addPressed) {
- //Add button pressed
- HandleAddButtonPress();
- delay(BUTTON_AUTOINC_DELAY);
- while (digitalRead(BUTTON_ADD) == LOW) {
- //Delay auto-shift
- HandleAddButtonPress();
- delay(BUTTON_HOLD_DELAY);
- }
- } else if (minusPressed) {
- //Minus button pressed
- HandleMinusButtonPress();
- delay(BUTTON_AUTOINC_DELAY);
- while (digitalRead(BUTTON_MINUS) == LOW) {
- //Delay auto-shift
- HandleMinusButtonPress();
- delay(BUTTON_HOLD_DELAY);
- }
- } else if (colorPressed) {
- //Color button pressed
- HandleColorButtonPress();
- delay(50);
- while (digitalRead(BUTTON_COLOR) == LOW) {
- //Wait for button up before continue
- delay(BUTTON_HOLD_DELAY);
- }
- //Debounce
- delay(50);
- } else if (modePressed) {
- }
- }
- void HandleColorButtonPress() {
- if (currentMode == 0) {
- //White mode
- //Only accept 0 (temp) or 1 (brightness)
- if (adjustingCatergory == 0) {
- adjustingCatergory = 1;
- setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, 0);
- } else {
- adjustingCatergory = 0;
- //Set control LED to white
- setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS);
- }
- }
- }
- void HandleAddButtonPress() {
- if (currentMode == 0) {
- //White Color Mode
- if (adjustingCatergory == 0) {
- //add 500 to K value
- values[0] = values[0] + 100;
- if (values[0] > 10000) {
- values[0] = 10000;
- }
- Serial.print("Updating color temperature to ");
- Serial.println(values[0]);
- } else if (adjustingCatergory == 1) {
- values[1] += 1;
- if (values[1] > MAX_BRIGHTNESS) {
- values[1] = MAX_BRIGHTNESS;
- }
- Serial.print("Updating brightness to ");
- Serial.println(values[1]);
- }
- setColorTemperature(values[0], values[1]);
- }
- }
- void HandleMinusButtonPress() {
- if (currentMode == 0) {
- //White Color Mode
- if (adjustingCatergory == 0) {
- //reduce 500 from K value
- values[0] = values[0] - 100;
- if (values[0] < 1500) {
- values[0] = 1500;
- }
- Serial.print("Updating color temperature to ");
- Serial.println(values[0]);
- } else if (adjustingCatergory == 1) {
- values[1] -= 1;
- if (values[1] < 0) {
- values[1] = 0;
- }
- Serial.print("Updating brightness to ");
- Serial.println(values[1]);
- }
- setColorTemperature(values[0], values[1]);
- }
- }
|