2 potentiometers color mixer

Posted by kantch

kantch's picture

 

This color mixer reproduces all the couples of two simple colors. The mix is controlled by the first potentiometer on input A0, the intensity is controlled by the second one on input A1. The LED inputs are 9, 10 and 11 for red green and blue respectively.
 
/* Potentiometer-controlled color mixer */
 
/*General Setup*/
byte RGBPins[] = {9, 10, 11}; //define where the LEDs are
byte white[] = {255,150,255}; //what is white (for calibration purposes)
byte red[] = {255,0,0}; //error color
byte potPins[] = {0, 1};
 
byte currentColor[3];
int potVals[2];
 
void setup() {
  for(int i=0; i<3; i++){
    pinMode(RGBPins[i],   OUTPUT);
  }
}
 
void loop (){
  for(int i=0; i<2; i++){
    potVals[i] = analogRead(potPins[i]);
  }
  specter(potVals[0], currentColor);
  intensity(potVals[1], currentColor);
  for(int i=0; i<3; i++){
    analogWrite(RGBPins[i], currentColor[i]);
  }
}
 
byte* specter(int pos, byte *color){
  if(pos > 0 && pos < 341){
        color[0] = pos*255.0/341.0;
        color[1] = 0;
        color[2] = 255 - pos*255.0/341.0;
      }
      if(pos > 341 && pos < 341*2){
        color[0] = 255 - (pos-341)*255.0/341.0;
        color[1] = (pos-341)*255.0/341.0;
        color[2] = 0;
      }
      if(pos > 341*2){
        color[0] = 0;
        color[1] = 255 - (pos-341*2)*255.0/341.0;
        color[2] = (pos-341*2)*255.0/341.0;
      }
  return color;
}
 
byte* intensity(int pos, byte *color){
  for(int i=0; i<3; i++){
    color[i] = color[i]*((float) pos)/1024.0;
  }
  return color;
}
0
Your rating: None
Tags: