buttons.ino 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. void handleButtonLogic() {
  2. bool modePressed = (digitalRead(BUTTON_MODE) == LOW);
  3. bool addPressed = (digitalRead(BUTTON_ADD) == LOW);
  4. bool colorPressed = (digitalRead(BUTTON_COLOR) == LOW);
  5. bool minusPressed = (digitalRead(BUTTON_MINUS) == LOW);
  6. if (addPressed) {
  7. //Add button pressed
  8. HandleAddButtonPress();
  9. delay(BUTTON_AUTOINC_DELAY);
  10. while (digitalRead(BUTTON_ADD) == LOW) {
  11. //Delay auto-shift
  12. HandleAddButtonPress();
  13. delay(BUTTON_HOLD_DELAY);
  14. }
  15. } else if (minusPressed) {
  16. //Minus button pressed
  17. HandleMinusButtonPress();
  18. delay(BUTTON_AUTOINC_DELAY);
  19. while (digitalRead(BUTTON_MINUS) == LOW) {
  20. //Delay auto-shift
  21. HandleMinusButtonPress();
  22. delay(BUTTON_HOLD_DELAY);
  23. }
  24. } else if (colorPressed) {
  25. //Color button pressed
  26. HandleColorButtonPress();
  27. delay(50);
  28. while (digitalRead(BUTTON_COLOR) == LOW) {
  29. //Wait for button up before continue
  30. delay(BUTTON_HOLD_DELAY);
  31. }
  32. //Debounce
  33. delay(50);
  34. } else if (modePressed) {
  35. }
  36. }
  37. void HandleColorButtonPress() {
  38. if (currentMode == 0) {
  39. //White mode
  40. //Only accept 0 (temp) or 1 (brightness)
  41. if (adjustingCatergory == 0) {
  42. adjustingCatergory = 1;
  43. setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, 0);
  44. } else {
  45. adjustingCatergory = 0;
  46. //Set control LED to white
  47. setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS);
  48. }
  49. }
  50. }
  51. void HandleAddButtonPress() {
  52. if (currentMode == 0) {
  53. //White Color Mode
  54. if (adjustingCatergory == 0) {
  55. //add 500 to K value
  56. values[0] = values[0] + 100;
  57. if (values[0] > 10000) {
  58. values[0] = 10000;
  59. }
  60. Serial.print("Updating color temperature to ");
  61. Serial.println(values[0]);
  62. } else if (adjustingCatergory == 1) {
  63. values[1] += 1;
  64. if (values[1] > MAX_BRIGHTNESS) {
  65. values[1] = MAX_BRIGHTNESS;
  66. }
  67. Serial.print("Updating brightness to ");
  68. Serial.println(values[1]);
  69. }
  70. setColorTemperature(values[0], values[1]);
  71. }
  72. }
  73. void HandleMinusButtonPress() {
  74. if (currentMode == 0) {
  75. //White Color Mode
  76. if (adjustingCatergory == 0) {
  77. //reduce 500 from K value
  78. values[0] = values[0] - 100;
  79. if (values[0] < 1500) {
  80. values[0] = 1500;
  81. }
  82. Serial.print("Updating color temperature to ");
  83. Serial.println(values[0]);
  84. } else if (adjustingCatergory == 1) {
  85. values[1] -= 1;
  86. if (values[1] < 0) {
  87. values[1] = 0;
  88. }
  89. Serial.print("Updating brightness to ");
  90. Serial.println(values[1]);
  91. }
  92. setColorTemperature(values[0], values[1]);
  93. }
  94. }