Reputation: 47
I'm trying to write some code that reads a voltage from 2 different pots and converts that to 3 pwm outputs that I can then send to an RGB LED. My idea is to use something like a colour map that is used to plot complex functions, but I'm not sure how to implement that. Any suggestions?
#define COLOUR_POT_INPUT 4
#define INTENSITY_POT_INPUT 3
#define LED_RED 9
#define LED_GREEN 10
#define LED_BLUE 11
float colour_angle;
float colour_radius;
float colour_x_value;
float colour_y_value;
int red_value;
int green_value;
int blue_value;
const float pi = 3.1415;
void setup() {
pinMode(COLOUR_POT_INPUT, INPUT);
pinMode(INTENSITY_POT_INPUT, INPUT);
pinMode(LED_RED, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
}
void loop() {
colour_angle = analogRead(COLOUR_POT_INPUT);
colour_radius = analogRead(INTENSITY_POT_INPUT);
colour_angle = map(colour_angle, 0, 1023, 0, 2*pi);
colour_radius = map(colour_radius, 0, 1023, 0, 255);
colour_x_value = colour_radius*cos(colour_angle);
colour_y_value = colour_radius*sin(colour_angle);
}
//Insert function here that maps colour x and y value to red green blue
value
Upvotes: 0
Views: 81
Reputation: 1565
Assuming colour_angle
and colour_radius
represent hue and saturation respectively, then you can use any HSL/HSV-to-RGB conversion code, with a fixed lightness/value.
Picking randomly from google results:
Upvotes: 3