mod_presets.ino 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Presets color palletes
  3. *
  4. * Cycle from the list below
  5. *
  6. */
  7. #define COLLOR_PALLETES_SIZE 12 //No of color pallete defined
  8. #define C_RED {255, 0, 0}
  9. #define C_ORANGE {255, 165, 0}
  10. #define C_YELLOW {255, 255, 0}
  11. #define C_YELLOWGREEN {170, 255, 0}
  12. #define C_GREEN {0, 255, 0}
  13. #define C_TEAL {0, 255, 166}
  14. #define C_TURQUOISE {64, 224, 208}
  15. #define C_CYAN {0, 255, 255}
  16. #define C_BLUE {0, 0, 255}
  17. #define C_PURPLE {255, 0, 255}
  18. #define C_LAVENDER {174, 0, 255}
  19. #define C_PINK {255, 0, 115}
  20. //Load the default runtime for RGB Mode
  21. int colorPalletes[COLLOR_PALLETES_SIZE][3] = {
  22. C_RED,
  23. C_ORANGE,
  24. C_YELLOW,
  25. C_YELLOWGREEN,
  26. C_GREEN,
  27. C_TEAL,
  28. C_TURQUOISE,
  29. C_CYAN,
  30. C_BLUE,
  31. C_LAVENDER,
  32. C_PURPLE,
  33. C_PINK
  34. };
  35. //initiate preset mode
  36. void loadPresetsDefault() {
  37. //Reset paramters
  38. adjustingCatergory = 0;
  39. //Set color pallete id to 0 (red), brightness to 50%, (last byte unused)
  40. values[0] = 0;
  41. values[1] = 50;
  42. values[2] = 0;
  43. //Update the color to the LEDs
  44. renderColorPallete(values[0]);
  45. }
  46. //Handlers for add / minus button
  47. void handlePresetsAdd() {
  48. if (adjustingCatergory == 0){
  49. //Change pallete
  50. values[0] = values[0] + 1;
  51. if (values[0] > COLLOR_PALLETES_SIZE - 1){
  52. values[0] = 0;
  53. }
  54. }else{
  55. //Change intensity
  56. values[1]++;
  57. if (values[1] > 100){
  58. values[1] = 100;
  59. blinkUpperLimit();
  60. }
  61. }
  62. renderColorPallete(values[0]);
  63. }
  64. void handlePresetsMinus(){
  65. if (adjustingCatergory == 0){
  66. //Change pallete
  67. values[0] = values[0] - 1;
  68. if (values[0] < 0){
  69. values[0] = COLLOR_PALLETES_SIZE - 1;
  70. }
  71. }else{
  72. //Change intensity
  73. values[1]--;
  74. if (values[1] < 1){
  75. values[1] = 1;
  76. blinkLowerLimit();
  77. }
  78. }
  79. renderColorPallete(values[0]);
  80. }
  81. void renderColorPallete(int palleteID){
  82. //Load the color pallete
  83. int palleteRGB[3] = {
  84. colorPalletes[values[0]][0],
  85. colorPalletes[values[0]][1],
  86. colorPalletes[values[0]][2]
  87. };
  88. //Set control LED color
  89. if (adjustingCatergory == 0){
  90. //Color pallete selection mode
  91. setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS);
  92. }else{
  93. //Brightness selection mode
  94. setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, 0);
  95. }
  96. //Adjust intensity
  97. palleteRGB[0] = int(float(palleteRGB[0]) * float(values[1]) / 100.0);
  98. palleteRGB[1] = int(float(palleteRGB[1]) * float(values[1]) / 100.0);
  99. palleteRGB[2] = int(float(palleteRGB[2]) * float(values[1]) / 100.0);
  100. /*
  101. //Debug output
  102. Serial.print(palleteRGB[0]);
  103. Serial.print(",");
  104. Serial.print(palleteRGB[1]);
  105. Serial.print(",");
  106. Serial.println(palleteRGB[2]);
  107. */
  108. //Update light color
  109. setLightColor(palleteRGB[0], palleteRGB[1], palleteRGB[2]);
  110. delay(100);
  111. }