/*
  共陰極RGB LED
*/
const byte r = 22;     //紅色接腳  
const byte g = 18;     //綠色
const byte b = 2;      //藍色
//-----------------------------------------------------------------------------
void setup() {
  pinMode(r, OUTPUT);       // 設定為輸出模式
  pinMode(b, OUTPUT);       // 設定為輸出模式
  pinMode(g, OUTPUT);       // 設定為輸出模式
}
//-----------------------------------------------------------------------------
void loop() { 
  setColor(0xFF, 0x00, 0x00);delay(1000);
  setColor(0xFF, 0x66, 0x00);delay(1000);
  setColor(0xFF, 0xFF, 0x00);delay(1000);
  setColor(0x00, 0xFF, 0x00);delay(1000);
  setColor(0x00, 0x00, 0xFF);delay(1000);
  setColor(0x00, 0xFF, 0xFF);delay(1000);
  setColor(0xFF, 0x00, 0xFF);delay(1000);
}

void setColor(int ValueR, int ValueG, int ValueB){
  analogWrite(r, ValueR);
  analogWrite(g, ValueG);
  analogWrite(b, ValueB);
}