Assignment #13 Output Devices



Introduction

I choose to use RGB SMD LED as an output device, and to test it while emitting variable light colors




Download File







int redPin = 8;
int greenPin = 7;
int bluePin = 6;
 
//uncomment this line if using a Common Anode LED
#define COMMON_ANODE
 
void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);  
}
 
void loop()
{
  setColor(255, 0, 0);  // red
  delay(100);
  setColor(0, 255, 0);  // blue
  delay(100);  
  setColor(77, 80, 0);  // purple
  delay(100);
}
 
void setColor(int red, int green, int blue)
{
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}