Monday 30 November 2015

Lab 5 - RGB LED

Purpose:
Utilize the RGB LED to made it shift colours

Equipment:
RGB LED (x1)
resistor (x1)
wires (x3)

Program Details:
i used the one off newinnovators.ca

Time to Program and Complete:
3 minutes

Results:
N/A

Photo/Video Proof:








































Program:
const int RED_LED_PIN = 9;
//sets a constant value for RED_LED_PIN
const int GREEN_LED_PIN = 10;
//sets a constant value for GREEN_LED_PIN
const int BLUE_LED_PIN = 11;
//sets a constant value for BLUE_LED_PIN

int redIntensity = 0;
//sets value for redIntensity
int greenIntensity = 0;
//sets value for redIntensity
int blueIntensity = 0;
//sets value for redIntensity

const int DISPLAY_TIME = 
//sets constant value for DISPLAY_TIME

void setup()
{
}
void loop()
//declares action
{
//start of loop
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5)
//if conditions met continue code
  {
//loop inside of loop
    redIntensity = 255-greenIntensity;
//sets new value for redIntensity
    analogWrite(GREEN_LED_PIN, greenIntensity);
//turns on GREEN_LED_PIN to value greenIntensity
    analogWrite(RED_LED_PIN, redIntensity);
//turns on RED_LED_PIN to value of redIntensity
    delay(DISPLAY_TIME);
//delay time for value for DISPLAY_TIME
  }
// end loop
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5)
//if conditions met continue code
  {
//loop inside of loop
    greenIntensity = 255-blueIntensity;
//sets new value for greenIntensity
    analogWrite(BLUE_LED_PIN, blueIntensity);
//turns on BLUE_PIN to value bluensity
    analogWrite(GREEN_LED_PIN, greenIntensity);
//turns on GREEN_LED_PIN to value greenIntensity
    delay(DISPLAY_TIME);
//delay time for value for DISPLAY_TIME
  }
//end of loop
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=5)
//if conditions met continue code
  {
//loop inside of loop
    blueIntensity = 255-redIntensity;
//sets new value for blueIntensity
    analogWrite(RED_LED_PIN, redIntensity);
//turns on RED_PIN to value redIntensity
    analogWrite(BLUE_LED_PIN, blueIntensity);
//turns on BLUE_PIN to value blueIntensity
    delay(DISPLAY_TIME);
//delay time for value for DISPLAY_TIME
  }
//end of loop
}


//end of loop
Program Modifications:
N/A

Helpful Tips:


References:
newinnovators.ca

No comments:

Post a Comment