Add white mode toggle and cleanup method return
This commit is contained in:
parent
3f4430a0d9
commit
5a2e8522f2
24
src/src.ino
24
src/src.ino
|
@ -14,6 +14,7 @@
|
||||||
#define POT_COLOR_PIN A1
|
#define POT_COLOR_PIN A1
|
||||||
#define NEO_PIN 6
|
#define NEO_PIN 6
|
||||||
#define NEO_PIX_NUM 2 // FIXME: this should be 5 for final build for safe lighting
|
#define NEO_PIX_NUM 2 // FIXME: this should be 5 for final build for safe lighting
|
||||||
|
#define PIN_WHITE 12 // Short Vout to this pin to change color to white
|
||||||
|
|
||||||
// Objects / values / etc
|
// Objects / values / etc
|
||||||
MAX1704 fuelGauge;
|
MAX1704 fuelGauge;
|
||||||
|
@ -24,9 +25,10 @@ uint8_t color;
|
||||||
bool always_on = false;
|
bool always_on = false;
|
||||||
Adafruit_NeoPixel neopix = Adafruit_NeoPixel(NEO_PIX_NUM, NEO_PIN, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel neopix = Adafruit_NeoPixel(NEO_PIX_NUM, NEO_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
||||||
|
bool white = false;
|
||||||
|
|
||||||
// Various function definitions
|
// Various function definitions
|
||||||
uint8_t* hsvToRgb(int h, double s, double v); // See end of file for implementation
|
void hsvToRgb(int h, double s, double v); // See end of file for implementation
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -42,6 +44,7 @@ void setup() {
|
||||||
pinMode(BUTTON_CAP_TOGGLE, INPUT);
|
pinMode(BUTTON_CAP_TOGGLE, INPUT);
|
||||||
pinMode(POT_BRIGHT_PIN, INPUT);
|
pinMode(POT_BRIGHT_PIN, INPUT);
|
||||||
pinMode(POT_COLOR_PIN, INPUT);
|
pinMode(POT_COLOR_PIN, INPUT);
|
||||||
|
pinMode(PIN_WHITE, INPUT);
|
||||||
|
|
||||||
// Setup / config MAX1704
|
// Setup / config MAX1704
|
||||||
fuelGauge.reset();
|
fuelGauge.reset();
|
||||||
|
@ -69,10 +72,17 @@ void loop() {
|
||||||
brightness = map(analogRead(POT_BRIGHT_PIN), 0, 1024, 0, 255); // Brightness (0-1023) mapped to 0-255
|
brightness = map(analogRead(POT_BRIGHT_PIN), 0, 1024, 0, 255); // Brightness (0-1023) mapped to 0-255
|
||||||
raw_color = analogRead(POT_COLOR_PIN); // Color (0-1024)
|
raw_color = analogRead(POT_COLOR_PIN); // Color (0-1024)
|
||||||
always_on = (digitalRead(BUTTON_CAP_TOGGLE) == HIGH); // Toggle button pressed == ALWAYS ON
|
always_on = (digitalRead(BUTTON_CAP_TOGGLE) == HIGH); // Toggle button pressed == ALWAYS ON
|
||||||
|
white = (digitalRead(PIN_WHITE) == HIGH); // Shorted pin to enable white color for LEDs
|
||||||
|
|
||||||
// Convert raw color value to position on a circle and then use the circle position to figure out color on a color wheel
|
// Set RGB array to values as appropriate
|
||||||
color = map(raw_color, 0, 1024, 0, 360);
|
if (white) {
|
||||||
hsvToRgb(color, 1, 1); // set rgb byte array
|
rgb[0] = rgb[1] = rgb[2] = 255;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Convert raw color value to position on a circle and then use the circle position to figure out color on a color wheel
|
||||||
|
color = map(raw_color, 0, 1024, 0, 360);
|
||||||
|
hsvToRgb(color, 1, 1); // set rgb byte array
|
||||||
|
}
|
||||||
|
|
||||||
// NeoPixel related
|
// NeoPixel related
|
||||||
for (uint8_t i=0; i<NEO_PIX_NUM; i++) {
|
for (uint8_t i=0; i<NEO_PIX_NUM; i++) {
|
||||||
|
@ -87,6 +97,8 @@ void loop() {
|
||||||
Serial.println(charge_percent);
|
Serial.println(charge_percent);
|
||||||
Serial.print("Brightness: ");
|
Serial.print("Brightness: ");
|
||||||
Serial.println(brightness);
|
Serial.println(brightness);
|
||||||
|
Serial.print("White: ");
|
||||||
|
Serial.println(white);
|
||||||
Serial.print("Color: ");
|
Serial.print("Color: ");
|
||||||
Serial.println(color);
|
Serial.println(color);
|
||||||
Serial.print("Red: ");
|
Serial.print("Red: ");
|
||||||
|
@ -104,7 +116,7 @@ void loop() {
|
||||||
|
|
||||||
// Convert degrees on a circle to color values
|
// Convert degrees on a circle to color values
|
||||||
// http://www.skylark-software.com/2011/01/arduino-notebook-rgb-led-and-color_21.html
|
// http://www.skylark-software.com/2011/01/arduino-notebook-rgb-led-and-color_21.html
|
||||||
uint8_t* hsvToRgb(int h, double s, double v) {
|
void hsvToRgb(int h, double s, double v) {
|
||||||
// Make sure our arguments stay in-range
|
// Make sure our arguments stay in-range
|
||||||
h = max(0, min(360, h));
|
h = max(0, min(360, h));
|
||||||
s = max(0, min(1.0, s));
|
s = max(0, min(1.0, s));
|
||||||
|
@ -112,7 +124,6 @@ uint8_t* hsvToRgb(int h, double s, double v) {
|
||||||
if(s == 0) {
|
if(s == 0) {
|
||||||
// Achromatic (grey)
|
// Achromatic (grey)
|
||||||
rgb[0] = rgb[1] = rgb[2] = round(v * 255);
|
rgb[0] = rgb[1] = rgb[2] = round(v * 255);
|
||||||
return rgb;
|
|
||||||
}
|
}
|
||||||
double hs = h / 60.0; // sector 0 to 5
|
double hs = h / 60.0; // sector 0 to 5
|
||||||
int i = floor(hs);
|
int i = floor(hs);
|
||||||
|
@ -155,5 +166,4 @@ uint8_t* hsvToRgb(int h, double s, double v) {
|
||||||
rgb[0] = round(r * 255.0);
|
rgb[0] = round(r * 255.0);
|
||||||
rgb[1] = round(g * 255.0);
|
rgb[1] = round(g * 255.0);
|
||||||
rgb[2] = round(b * 255.0);
|
rgb[2] = round(b * 255.0);
|
||||||
return rgb;
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue