Color LED

Part Used

  • 3 \(100\Omega\) resistors

  • 1 jumper wire

Time Spent

Approximately 2 hours

The Code

int redPin = 8;
int greenPin = 10;
int bluePin = 12;

int red[3] = {255,0,0};
int green[3] = {0,255,0};
int blue[3] = {0,0,255};
int yellow[3] = {255,255,0};
int purple[3]= {80,0,80};
int cyan[3] = {0,255,255};

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop()
{
dash(yellow);
SOS(red);
}


void loopColor(int timeDelay){
  setColor(red);  // red
  delay(timeDelay);
  setColor(green);  // green
  delay(timeDelay);
  setColor(blue);  // blue
  delay(timeDelay);
  setColor(yellow);  // yellow
  delay(timeDelay);
  setColor(purple);  // purple
  delay(timeDelay);
  setColor(cyan);  // aqua
  delay(timeDelay);
}

void setColor(int color[3])
{
  analogWrite(redPin, color[0]);
  analogWrite(greenPin, color[1]);
  analogWrite(bluePin, color[2]);
}

void dot(int color[3]){
  setColor(color);
  delay(300);
  analogWrite(redPin, 0);
  analogWrite(greenPin, 0);
  analogWrite(bluePin, 0);
  delay(300);
}

void dash(int color[3]){
  setColor(color);
  delay(600);
  analogWrite(redPin, 0);
  analogWrite(greenPin, 0);
  analogWrite(bluePin, 0);
  delay(600);
}

void SOS(int color[3]){
dot(color);
dot(color);
dot(color);
dash(color);
dash(color);
dash(color);
dot(color);
dot(color);
dot(color);
}

Major Issues

  • The code and the color LED were straitforward. The only issue I had was that there was only one jumper wire in my arduino kit. So I used some resistors instead. It worked pretty well, except that resistors, unlike jumpers, may connect if they cross over each other.

  • The LED was not of very good quality. The yellow and green looked almost identical with that LED. I had to lower the green input by half to make light appear to be yellow. It took us (the class) a while to figure out that there was nothing wrong with my code but with the LED.

Results



Looping colors

Sending SOS signal in morse code