Hi all,
I have a tiny LED that is soldered onto a breadboard. The three colours go to to these pins.
redPin = 11;
greenPin = 10;
bluePin = 9;
In my situation the values that you would use for an analogWrite need to be inverted. Meaning that if i want the red colour to be 255, it would need to output 0 to be on full (LOW = ON , HIGH = OFF) i cannot change this as this is meant for the project i am doing.
I want to be able to run the RGB values at 120Hz for 8ms (8000microseconds)
The formula to do this is the following:
(Value/255) * 8000
Here is a quick scenario:
(Serial Monitor)
Red Value ( 0-255 ): 255
Green Value (0-255): 190
Blue Value(0-255): 0
(Code)
(Because of the wiring these values would need to be inverted)
tRed = 255 - Red Value
tGreen = 255 - Green Value
tBlue = 255 - Blue Value
tRed = 0 (Fully On)
tGreen = 65 (Partially on)
tBlue = 255 (Completly Off)
The Code will the need to work out its delay to be turned on by doing the formula
formulaR = (tRed/255.0)*8000;
formulaG = (tGreen/255.0)*8000;
formulaB = (tBlue/255.0)*8000;
formulaR = 0
formulaG = 2039
formulaB = 8000;
Now this is the part that i am stuck at in the code. I need the red to be at LOW for the whole 8000 microseconds. the green to be on for 2039 microseconds. but then i need Blue to be off for 8000 microseconds because the input was originally 0 meaning that there should be no Blue at all.
I dont know if i have explained this properly. If you need any more information just comment:)
I need to be writing this in digitalWrite form aswell.
This is what i have so far
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
String msg1 = "Enter Red Value (0-255): ";
String msg2 = "Enter Green Value (0-255): ";
String msg3 = "Enter Blue Value(0-255): ";
int tR,tRa;
int tG,tGa;
int tB,tBa;
int formulaR;
int formulaG;
int formulaB;
void setup()
{
Serial.begin(9600);
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
digitalWrite(redPin,HIGH);
digitalWrite(greenPin,HIGH);
digitalWrite(bluePin,HIGH);
}
void loop()
{
Serial.print(msg1);
while(Serial.available()==0)
{
}
tR = Serial.parseInt();
Serial.println(tR);
Serial.print(msg2);
while(Serial.available()==0)
{
}
tG = Serial.parseInt();
Serial.println(tG);
Serial.print(msg3);
while(Serial.available()==0)
{
}
tB = Serial.parseInt();
Serial.println(tB);
tRa = 255 - tR;
tGa = 255 - tG;
tBa = 255 - tB;
formulaR = (tRa/255.0)*8000;
formulaG = (tGa/255.0)*8000;
formulaB = (tBa/255.0)*8000;
}