Browse Source

init commit

Toby Chui 6 months ago
parent
commit
e40e7da9d1

+ 7 - 0
autopush.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+echo Enter commit notes:
+read commitmsg
+git pull
+git add *
+git commit -m "$commitmsg"
+git push

+ 103 - 0
firmware/rgbfill/buttons.ino

@@ -0,0 +1,103 @@
+
+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]);
+  }
+}

+ 98 - 0
firmware/rgbfill/lib/tempcolor.cpp

@@ -0,0 +1,98 @@
+// tempcolor.cpp
+// Travis Llado, 2016
+
+// Temp.Color converts light temperatures from 1000K to
+// 40,000K, as well as desired brightness, into light
+// color codes for WS2812 LEDs.
+// Conversion data is provided by Mitch Charity at Vendian.
+// (http://www.vendian.org/mncharity/dir3/blackbody/)
+
+#include "tempcolor.h"
+
+tempClass temp;
+
+// color
+// Accepts two values (for temperature and brightness) and
+// returns the corresponding neopixel color code (32b int)
+uint32_t tempClass::color(double T, double brite) {
+  if(brite >= 0.0 && brite <= 1.0) {
+    uint8_t Red = R(T)*brite;
+    uint8_t Grn = G(T)*brite;
+    uint8_t Blu = B(T)*brite;
+
+    if(format == rgb)
+      return (uint32_t)Red << 16 | (uint32_t)Grn <<  8 | Blu;
+    else
+      return (uint32_t)Grn << 16 | (uint32_t)Red <<  8 | Blu;
+  }
+  return 0;
+}
+
+void tempClass::RGB() {
+  format = rgb;
+}
+
+void tempClass::GRB() {
+  format = grb;
+}
+
+uint8_t tempClass::R(double T) {
+  if(T >= -1.0) {
+    if(T <= 0.0)
+      return 255*(1);
+    if(T <= 1.0)
+      return 255*(-0.990*T*T*T + 2.34*T*T - 1.99*T + 0.970);
+  }
+  return 0;
+}
+
+uint8_t tempClass::G(double T) {
+  if(T >= -1.0) {
+    if(T <= 0.0)
+      return 255*(-0.402*T*T*T - 0.211*T*T + 1.09*T + 0.958);
+    if(T <= 1.0)
+      return 255*(-0.542*T*T*T + 1.37*T*T - 1.28*T + 0.941);
+  }
+  return 0;
+}
+
+uint8_t tempClass::B(double T) {
+  if(T >= -1.0) {
+    if(T <= -0.7)
+      return 255*(0);
+    if(T <= 0.0)
+      return 255*(0.0117*T*T*T + 2.05*T*T + 2.85*T + 1.00);
+    if(T <= 1.0)
+      return 255*(1);
+  }
+  return 0;
+}
+
+// overloaded functions so user can give color and brightness
+// as either double or int
+uint32_t tempClass::color(double T, int brite) {
+  double f_brite = (double)brite / 255.0;
+  return color(T,f_brite);
+}
+
+uint32_t tempClass::color(int T, double brite) {
+  double f_T = (log(T) - 8.79) / 1.8;
+  return color(f_T,brite);
+}
+
+uint32_t tempClass::color(long int T, double brite) {
+  double f_T = (log(T) - 8.79) / 1.8;
+  return color(f_T,brite);
+}
+
+uint32_t tempClass::color(int T, int brite) {
+  double f_T = (log(T) - 8.79) / 1.8;
+  double f_brite = (double)brite / 255.0;
+  return color(f_T,f_brite);
+}
+
+uint32_t tempClass::color(long int T, int brite) {
+  double f_T = (log(T) - 8.79) / 1.8;
+  double f_brite = (double)brite / 255.0;
+  return color(f_T,f_brite);
+}

+ 37 - 0
firmware/rgbfill/lib/tempcolor.h

@@ -0,0 +1,37 @@
+// tempcolor.h
+// Travis Llado, 2016
+
+// Temp.Color converts light temperatures from 1000K to
+// 40,000K, as well as desired brightness, into light
+// color codes for WS2812 LEDs.
+// Conversion data is provided by Mitch Charity at Vendian.
+// (http://www.vendian.org/mncharity/dir3/blackbody/)
+
+#ifndef TEMPCOLOR_H
+#define TEMPCOLOR_H
+
+#include "Arduino.h"
+
+#define rgb 0
+#define grb 1
+
+class tempClass {
+  public:
+  uint32_t color(double temp, double brightness);
+  uint32_t color(double temp, int brightness);
+  uint32_t color(int temp, double brightness);
+  uint32_t color(long int temp, double brightness);
+  uint32_t color(int temp, int brightness);
+  uint32_t color(long int temp, int brightness);
+  void RGB();
+  void GRB();
+  private:
+  uint8_t R(double);
+  uint8_t G(double);
+  uint8_t B(double);
+  bool format;
+};
+
+extern tempClass temp;
+
+#endif

+ 46 - 0
firmware/rgbfill/mode_white.ino

@@ -0,0 +1,46 @@
+//Set color temperature set the LED RGB Values based on given temperature K value and brigheness level (0 - 255)
+void setColorTemperature(int temperatureK, int brightnessLevel) {
+  
+  // Check if brightness is within the valid range [0, 1]
+  if (brightnessLevel > MAX_BRIGHTNESS) {
+    brightnessLevel = MAX_BRIGHTNESS;
+  } else if (brightnessLevel < 0) {
+    brightnessLevel = 0;
+  }
+
+  //Normalize the brightness value
+  double brightness = float(brightnessLevel) / 255.0;
+  double normalizedTemperature = (log(temperatureK) - 8.79) / 1.8;
+
+  int red = 0;
+  int green = 0;
+  int blue = 0;
+
+  normalizedTemperature = constrain(normalizedTemperature, -1.0, 1.0);
+  if (normalizedTemperature <= 0){
+    red = 255;
+    green = int(255 * (-0.402 * normalizedTemperature * normalizedTemperature * normalizedTemperature - 0.211 * normalizedTemperature * normalizedTemperature + 1.09* normalizedTemperature + 0.958));
+  }else{
+    red = int(255 * (-0.990 * normalizedTemperature * normalizedTemperature * normalizedTemperature + 2.34 * normalizedTemperature * normalizedTemperature - 1.99 * normalizedTemperature + 0.970));
+    green = int(255 * (-0.542 * normalizedTemperature * normalizedTemperature * normalizedTemperature + 1.37 * normalizedTemperature * normalizedTemperature - 1.28 * normalizedTemperature + 0.941));
+  }
+
+  if (normalizedTemperature <= -0.7){
+     blue = int(0);
+  }else if (normalizedTemperature <= 0.0){
+     blue = int(255 * (0.0117*normalizedTemperature*normalizedTemperature*normalizedTemperature + 2.05*normalizedTemperature*normalizedTemperature + 2.85*normalizedTemperature + 1.00));
+  }else{
+     blue = int(255 * (1.0));
+  }
+
+  red = red * brightness;
+  green = green * brightness;
+  blue = blue * brightness;
+  
+  Serial.println(red);
+  Serial.println(green);
+  Serial.println(blue);
+
+  //Set all the LEDs to desired color temperature
+  setLightColor(red, green, blue);
+}

+ 98 - 0
firmware/rgbfill/rgbfill.ino

@@ -0,0 +1,98 @@
+/*
+
+    RGB Fill Lights
+    Author: tobychui
+
+    This is the firmware for tobychui's
+    Programmable RGB Fill Light
+
+    Recommend compiling with following board profiles
+    - Wemos D1 Mini
+
+
+*/
+#include <Adafruit_NeoPixel.h>
+#include "lib/tempcolor.h"
+
+// Hardware Configs
+#define PIN D4
+#define NUM_LEDS 46
+#define BUTTON_MODE D7
+#define BUTTON_ADD D6
+#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 MAX_CTRLBRIGHTNESS 32 //Max brightness for signaling LED (the one above the button)
+//Runtimes
+/*
+   Current Mode
+   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)
+   3 = Presets Mode (+/- Change the preset profile currently using)
+*/
+int currentMode = 0;
+
+/*
+   Adjusting Catergory
+
+   [White Mode]
+   0 = Color Temperature (K)
+   1 = Brightness
+
+
+*/
+int adjustingCatergory = 0;
+
+/*
+   Color Values
+   [White Mode]
+   TEMP, Brightness, (un-used)
+
+   [RGB Mode]
+   R, G, B
+
+*/
+int values[] = {0, 0, 0};
+
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
+
+//Set the current control LED color
+void setControlLEDColor(int r, int g, int b){
+  strip.setPixelColor(0, strip.Color(r, g, b));
+  strip.show();
+}
+
+//Set the current LED light color by given RGB values
+void setLightColor(int r, int g, int b) {
+  for (int i = 1; i < NUM_LEDS; i++) {
+    strip.setPixelColor(i, strip.Color(r, g, b));
+  }
+  strip.show();
+}
+void setup() {
+  Serial.begin(115200);
+
+  //Set the buttons to input pin
+  pinMode(BUTTON_MODE, INPUT);
+  pinMode(BUTTON_ADD, INPUT);
+  pinMode(BUTTON_COLOR, INPUT);
+  pinMode(BUTTON_MINUS, INPUT);
+  strip.begin();
+
+  // Initialize all pixels to natural warm white light
+  setColorTemperature(4000, MAX_BRIGHTNESS/2);
+  values[0] = 4000;
+  values[1] = MAX_BRIGHTNESS/2;
+
+  //Set ctrl LED to low brightness white
+  setControlLEDColor(MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS, MAX_CTRLBRIGHTNESS);
+}
+
+void loop() {
+  handleButtonLogic();
+
+}

BIN
prod/Gerber_RGB Photography Light.zip