Created
July 3, 2020 21:33
-
-
Save jywarren/6e174d0f5c203c6feec0804013b2f8a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Thermal fishing | |
* https://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/ | |
*/ | |
// Pins 3, 5, and 6 are the red, green and blue LEDs on the Arduino board. | |
// give them names: | |
int redPin = 3; | |
int greenPin = 5; | |
int bluePin = 6; | |
int thermistorPin = 1; | |
int thermistorValue; | |
int startVal; | |
void setup() { | |
// start with current ambient temp = blue/cold | |
startVal = analogRead(thermistorPin); // 0-1023 | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
thermistorValue = analogRead(thermistorPin); // 0-1023 | |
int hue = map(thermistorValue, startVal, startVal + 4, 250, 0); // map it to 0-360 | |
Serial.print(thermistorValue); | |
Serial.print(" - "); | |
Serial.println(hue); | |
setLedColorHSV(hue, 1, 1); | |
} | |
// http://www.hobbitsandhobos.com/wp-content/uploads/2011/06/colorWheel.png | |
// Convert a given HSV (Hue Saturation Value) to RGB (Red Green Blue) | |
// and set the led to the color | |
// h is hue value, integer between 0 and 360 | |
// s is saturation value, double between 0 and 1 | |
// v is value, double between 0 and 1 | |
// http://splinter.com.au/blog/?p=29 | |
void setLedColorHSV(int h, double s, double v) { | |
double r=0; | |
double g=0; | |
double b=0; | |
double hf=h/60.0; | |
int i=(int)floor(h/60.0); | |
double f = h/60.0 - i; | |
double pv = v * (1 - s); | |
double qv = v * (1 - s*f); | |
double tv = v * (1 - s * (1 - f)); | |
switch (i) | |
{ | |
case 0: // rojo dominante | |
r = v; | |
g = tv; | |
b = pv; | |
break; | |
case 1: // verde | |
r = qv; | |
g = v; | |
b = pv; | |
break; | |
case 2: | |
r = pv; | |
g = v; | |
b = tv; | |
break; | |
case 3: // azul | |
r = pv; | |
g = qv; | |
b = v; | |
break; | |
case 4: | |
r = tv; | |
g = pv; | |
b = v; | |
break; | |
case 5: // rojo | |
r = v; | |
g = pv; | |
b = qv; | |
break; | |
} | |
// set each component to a integer value between 0 and 255 | |
int red = constrain(255-(int)255*r,0,255); | |
int green = constrain(255-(int)255*g,0,255); | |
int blue = constrain(255-(int)255*b,0,255); | |
setLedColor(red,green,blue); | |
} | |
void setLedColor(int red, int green, int blue) { | |
analogWrite(redPin, red); | |
analogWrite(greenPin, green); | |
analogWrite(bluePin, blue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment