Friday, 27 June 2014

Colour Mixing of RGB

I was unable to get the diffused common anode RGB led. So I put red, blue and green LEDs together using a tape. Now I could notice the colour mixing of intersection.

In the hex code of colours, each 2 characters represent the value of red, green and blue sequentially. To convert the hex code of a colour into its number form, 0x  is prefixed to the hex value.

For example the code for Deep pink is #FF1493 . So its red value is FF, green is 14, blue is 93.
So in my program, setcolour(0xFF, 0x93, 0x14) gives me deep pink

Breadboard Layout:


Code:

int red=11;
int blue=10;
int green=9;
void setup()
{
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
}

void loop()
{
  setcolour(255,0,0);//red
  delay(2000);
  setcolour(0,255,0);//blue
  delay(2000);
  setcolour(0,0,255);//green
  delay(2000);
  // #FFFF66: yellow
  setcolour(0xFF, 0xFF, 0x66);
    delay(4000);
  setcolour(0xFF, 0x93, 0x14);//pink
     delay(4000);
  //spring green #00FA9A
  setcolour(0x00,0x9A, 0xFA);
  delay(4000);
}

void setcolour(int red_value, int blue_value, int green_value)
{
  analogWrite(red, red_value);
  analogWrite(blue, blue_value);
  analogWrite(green, green_value);
}

No comments:

Post a Comment