Browse Source

Added preset mode

Toby Chui 1 year ago
parent
commit
c21510d5f5

+ 29 - 8
firmware/rgbfill/buttons.ino

@@ -14,6 +14,7 @@ void handleButtonLogic() {
       HandleAddButtonPress();
       delay(BUTTON_HOLD_DELAY);
     }
+    delay(BUTTON_DEBOUNCE);
   } else if (minusPressed) {
     //Minus button pressed
     HandleMinusButtonPress();
@@ -23,16 +24,17 @@ void handleButtonLogic() {
       HandleMinusButtonPress();
       delay(BUTTON_HOLD_DELAY);
     }
+    delay(BUTTON_DEBOUNCE);
   } else if (colorPressed) {
     //Color button pressed
     HandleColorButtonPress();
-    delay(50);
+    delay(BUTTON_DEBOUNCE);
     while (digitalRead(BUTTON_COLOR) == LOW) {
       //Wait for button up before continue
       delay(BUTTON_HOLD_DELAY);
     }
     //Debounce
-    delay(50);
+    delay(BUTTON_DEBOUNCE);
 
   } else if (modePressed) {
     HandleModeButtonPress();
@@ -41,7 +43,7 @@ void handleButtonLogic() {
       delay(BUTTON_HOLD_DELAY);
     }
     //Debounce
-    delay(50);
+    delay(BUTTON_DEBOUNCE);
   }
 
 }
@@ -50,7 +52,7 @@ void handleButtonLogic() {
 void HandleModeButtonPress() {
   //Update the mode number
   currentMode += 1;
-  if (currentMode > 3) {
+  if (currentMode > 2) {
     currentMode = 0;
   }
 
@@ -64,8 +66,7 @@ void HandleModeButtonPress() {
     loadRGBModeDefault();
   } else if (currentMode == 2) {
     Serial.println("Switched to Color Palette Mode");
-  } else if (currentMode == 3) {
-    Serial.println("Switched to Preset Mode");
+    loadPresetsDefault();
   }
 
 }
@@ -84,6 +85,7 @@ void HandleColorButtonPress() {
       setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS);
     }
   } else if (currentMode == 1) {
+    //RGB Adjustable Mode
     if (adjustingCatergory == 0) {
       //Red -> Green
       adjustingCatergory = 1;
@@ -98,6 +100,17 @@ void HandleColorButtonPress() {
       //Set LED to yellow for brightness
       setControlLEDColor(MAX_CTRLBRIGHTNESS, 0, 0);
     }
+  } else if (currentMode == 2){
+    //Color pallete mode
+    if (adjustingCatergory == 0) {
+      //Enter brightness control mode
+      adjustingCatergory = 1;
+      setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, 0);
+    }else{
+      //Enter pallete select mode
+      adjustingCatergory = 0;
+      renderColorPallete(values[0]);
+    }
   }
 }
 
@@ -124,7 +137,11 @@ void HandleAddButtonPress() {
     }
     setColorTemperature(values[0], values[1]);
   } else if (currentMode == 1) {
+    //RGB Color Mode 
     handleRGBModeAdd();
+  } else if (currentMode == 2){
+    //Color Pallete Mode
+    handlePresetsAdd();
   }
 }
 
@@ -134,8 +151,8 @@ void HandleMinusButtonPress() {
     if (adjustingCatergory == 0) {
       //reduce 500 from K value
       values[0] = values[0] - 100;
-      if (values[0] < 1500) {
-        values[0] = 1500;
+      if (values[0] < 2500) {
+        values[0] = 2500;
         blinkLowerLimit();
       }
 
@@ -152,6 +169,10 @@ void HandleMinusButtonPress() {
     }
     setColorTemperature(values[0], values[1]);
   } else if (currentMode == 1) {
+    //RGB Color Mode 
     handleRGBModeMinus();
+  } else if (currentMode == 2){
+    //Color Pallete Mode
+    handlePresetsMinus();
   }
 }

+ 123 - 0
firmware/rgbfill/mod_presets.ino

@@ -0,0 +1,123 @@
+/*
+ *  Presets color palletes
+ *  
+ *  Cycle from the list below
+ *  
+ */
+
+#define COLLOR_PALLETES_SIZE 12 //No of color pallete defined
+#define C_RED {255, 0, 0}
+#define C_ORANGE {255, 165, 0}
+#define C_YELLOW {255, 255, 0}
+#define C_YELLOWGREEN {170, 255, 0}
+#define C_GREEN {0, 255, 0}
+#define C_TEAL {0, 255, 166}
+#define C_TURQUOISE {64, 224, 208}
+#define C_CYAN {0, 255, 255}
+#define C_BLUE {0, 0, 255}
+#define C_PURPLE {255, 0, 255}
+#define C_LAVENDER {174, 0, 255}
+#define C_PINK {255, 0, 115}
+
+
+//Load the default runtime for RGB Mode
+int colorPalletes[COLLOR_PALLETES_SIZE][3] = {
+  C_RED, 
+  C_ORANGE, 
+  C_YELLOW,
+  C_YELLOWGREEN, 
+  C_GREEN, 
+  C_TEAL, 
+  C_TURQUOISE, 
+  C_CYAN, 
+  C_BLUE, 
+  C_LAVENDER, 
+  C_PURPLE, 
+  C_PINK
+ };
+
+//initiate preset mode
+void loadPresetsDefault() {
+  //Reset paramters
+  adjustingCatergory = 0;
+  //Set color pallete id to 0 (red), brightness to 50%, (last byte unused)
+  values[0] = 0;
+  values[1] = 50;
+  values[2] = 0;
+
+  //Update the color to the LEDs
+  renderColorPallete(values[0]);
+}
+
+//Handlers for add / minus button
+void handlePresetsAdd() {
+  if (adjustingCatergory == 0){
+    //Change pallete
+    values[0] = values[0] + 1;
+    if (values[0] > COLLOR_PALLETES_SIZE - 1){
+      values[0] = 0;
+    }
+  }else{
+    //Change intensity
+    values[1]++;
+    if (values[1] > 100){
+      values[1] = 100;
+      blinkUpperLimit();
+    }
+  }
+  renderColorPallete(values[0]);
+}
+
+void handlePresetsMinus(){
+  if (adjustingCatergory == 0){
+    //Change pallete
+    values[0] = values[0] - 1;
+    if (values[0] < 0){
+      values[0] = COLLOR_PALLETES_SIZE - 1;
+    }
+  }else{
+    //Change intensity
+    values[1]--;
+    if (values[1] < 1){
+      values[1] = 1;
+      blinkLowerLimit();
+    }
+  }
+  renderColorPallete(values[0]);
+}
+
+void renderColorPallete(int palleteID){
+  //Load the color pallete
+    int palleteRGB[3] = {
+      colorPalletes[values[0]][0], 
+      colorPalletes[values[0]][1], 
+      colorPalletes[values[0]][2]
+    };
+
+    //Set control LED color
+    if (adjustingCatergory == 0){
+      //Color pallete selection mode
+      setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS);
+    }else{
+      //Brightness selection mode
+      setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, 0);
+    }
+    
+     
+    //Adjust intensity
+    palleteRGB[0] = int(float(palleteRGB[0]) * float(values[1]) / 100.0);
+    palleteRGB[1] = int(float(palleteRGB[1]) * float(values[1]) / 100.0);
+    palleteRGB[2] = int(float(palleteRGB[2]) * float(values[1]) / 100.0);
+
+    /*
+    //Debug output
+    Serial.print(palleteRGB[0]);
+    Serial.print(",");
+    Serial.print(palleteRGB[1]);
+    Serial.print(",");
+    Serial.println(palleteRGB[2]);
+    */
+    
+    //Update light color
+    setLightColor(palleteRGB[0], palleteRGB[1], palleteRGB[2]);
+}

+ 11 - 3
firmware/rgbfill/mode_rgb.ino

@@ -1,8 +1,16 @@
+/*
+ * RGB Mode
+ * 
+ * Allow user to adjust R/G/B channel 
+ * seperately
+ * 
+ * 
+ */
 //Load the default runtime for RGB Mode
 void loadRGBModeDefault() {
-  values[0] = MAX_BRIGHTNESS; //R
-  values[1] = MAX_BRIGHTNESS; //G
-  values[2] = MAX_BRIGHTNESS; //B
+  values[0] = MAX_BRIGHTNESS/2; //R
+  values[1] = MAX_BRIGHTNESS/2; //G
+  values[2] = MAX_BRIGHTNESS/2; //B
   adjustingCatergory = 0;
 
   //Set current controlling to red

+ 8 - 0
firmware/rgbfill/mode_white.ino

@@ -50,6 +50,14 @@ void setColorTemperature(int temperatureK, int brightnessLevel) {
   green = green * brightness;
   blue = blue * brightness;
 
+  //Make sure non of the values goes over 255
+  if (red > 255){
+    red = 255;
+  }
+  //Green usually wont go over 255
+  if (blue > 255){
+    blue = 255;
+  }
   Serial.println(red);
   Serial.println(green);
   Serial.println(blue);

+ 11 - 5
firmware/rgbfill/rgbfill.ino

@@ -21,9 +21,10 @@
 #define BUTTON_COLOR D5
 #define BUTTON_MINUS D0
 
-#define BUTTON_AUTOINC_DELAY 500 //Delay before auto increments
-#define BUTTON_HOLD_DELAY 50 //Auto-increment delays
-#define MAX_BRIGHTNESS 128 //Make sure the battery you using can output the current required by LEDs
+#define BUTTON_AUTOINC_DELAY 300 //Delay before auto increments
+#define BUTTON_HOLD_DELAY 100 //Auto-increment delays
+#define BUTTON_DEBOUNCE 50 //Naive debounce delay in ms
+#define MAX_BRIGHTNESS 256 //Make sure the battery you using can output the current required by LEDs
 #define MAX_CTRLBRIGHTNESS 32 //Max brightness for signaling LED (the one above the button)
 //Runtimes
 /*
@@ -31,7 +32,6 @@
    0 = White Mode (+/- Change the K value of the light)
    1 = RGB Mode (+/C/- Change the RGB values of the light)
    2 = Pure Color Mode (C Change the default color palletes, +- change brightness offset)
-   3 = Presets Mode (+/- Change the preset profile currently using)
 */
 int currentMode = 0;
 
@@ -47,6 +47,10 @@ int currentMode = 0;
    1 = Green
    2 = Blue
 
+   [Pallete Mode]
+   0 = Color Pallete
+   1 = Brightness
+
 */
 int adjustingCatergory = 0;
 
@@ -58,6 +62,9 @@ int adjustingCatergory = 0;
    [RGB Mode]
    R, G, B
 
+   [Pallete Mode]
+   PalleteID, Brightness, (unused)
+
 */
 int values[] = {0, 0, 0};
 int currentCtrlLedRgb[] = {0,0,0};
@@ -96,5 +103,4 @@ void setup() {
 
 void loop() {
   handleButtonLogic();
-
 }