Arduino Spectrum Slider
Parts
1x long blue jumper cable
1x long red jumper cable
2x short black jumper cable
1x of each RGB jumper cables
Tri color led
Potentiometer
All can be gotten in sidekick kit
Schematics
Code
Copy and paste. If common cathode as RGB values to 0 instead of subtracting.
int rPin = 11;
int gPin = 10; int bPin = 9; float rPinBrightness; float gPinBrightness; float bPinBrightness; float value; float mval; float Red; float Green; float Blue; float factor; void setup() { // put your setup code here, to run once:
}
void color() { mval = analogRead(A1); value = map(mval, 0, 1023, 380, 650);
if((value >= 380) && (value<440)){ Red = -(value - 440) / (440 - 380); Green = 0.0; Blue = 1.0; }else if((value >= 440) && (value<490)){ Red = 0.0; Green = (value - 440) / (490 - 440); Blue = 1.0; }else if((value >= 490) && (value<510)){ Red = 0.0; Green = 1.0; Blue = -(value - 510) / (510 - 490); }else if((value >= 510) && (value<580)){ Red = (value - 510) / (580 - 510); Green = 1.0; Blue = 0.0; }else if((value >= 580) && (value<645)){ Red = 1.0; Green = -(value - 645) / (645 - 580); Blue = 0.0; }else if((value >= 645) && (value<781)){ Red = 1.0; Green = 0.0; Blue = 0.0; }else{ Red = 0.0; Green = 0.0; Blue = 0.0; }; if((value >= 380) && (value<420)){ factor = 0.3 + 0.7*(value - 380) / (420 - 380); }else if((value >= 420) && (value<701)){ factor = 1.0; }else if((value >= 701) && (value<781)){ factor = 0.3 + 0.7*(780 - value) / (780 - 700); }else{ factor = 0.0; };
}
void loop() { // put your main code here, to run repeatedly: color(); analogWrite(rPin, 255 - Red*100*factor); analogWrite(gPin, 255 - Green*100*factor); analogWrite(bPin, 255 - Blue*100*factor); delay(10); }