Hello,
I'm passing three values (R,G,B) to Arduino from a Python file (via pyserial) and lighting up the LED included in the starter kit (which I believe is 'common cathode') as discussed in project 4 "Color Mixing Lamp".
Everything is 'working' and the LED shows expected results for values like:
255, 0, 0 - Shows Red
0, 255, 0 - Shows Green
0, 0, 255 - Shows Blue
Some mixed colors however, don't appear as they would, for example, in a color chooser application.
For example the LED output for "19, 235, 26" appears light purple, whereas it should actually appear lime green.
See
http://www.colorspire.com/rgb-color-wheel for an example.
Is this a 'known' scenario?
Perhaps if I used more expensive LED's or a RGB led strip, the colors would be more accurate?
Thank You.
Arduino Code// digital output pin numbers
const int digitalOutputPinForRedLED = 9;
const int digitalOutputPinForGreenLED = 10;
const int digitalOutputPinForBlueLED = 11;
// global variables
int valueOfRed = 0;
int valueOfGreen = 0;
int valueOfBlue = 0;
int x = 1;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// set digital pin modes
pinMode(digitalOutputPinForRedLED,OUTPUT);
pinMode(digitalOutputPinForGreenLED,OUTPUT);
pinMode(digitalOutputPinForBlueLED,OUTPUT);
}
void loop() {
if (Serial.available()) {
if (x==1) {
valueOfRed = Serial.read();
Serial.print("Red: ");
Serial.println(valueOfRed);
analogWrite(digitalOutputPinForRedLED, valueOfRed);
}
else if (x==2) {
valueOfGreen = Serial.read();
Serial.print("Green: ");
Serial.println(valueOfGreen);
analogWrite(digitalOutputPinForGreenLED, valueOfGreen);
}
else if (x==3) {
valueOfBlue = Serial.read();
Serial.print("Blue: ");
Serial.println(valueOfBlue);
analogWrite(digitalOutputPinForBlueLED, valueOfBlue);
}
x++;
}
else {
x = 1;
}
delay(1);
}
Python Codeimport serial
import struct
ser = serial.Serial('/dev/ttyACM0', 9600)
red_value = int(request.GET.redvalue)
green_value = int(request.GET.greenvalue)
blue_value = int(request.GET.bluevalue)
ser.write(struct.pack('>3B', red_value, green_value, blue_value))