// --------------------------------------------------------------------------------
/*

10 三色 LED 調色盤

[學習重點]

1. 認識 RGB LED

2. 認識三原色

[挑戰]

- 嘗試調出紅橙黃綠青藍紫七色


Created by Jason on 10 Aug 2022.

*/
// --------------------------------------------------------------------------------

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int potRPin = A1; // 定義接收紅色可變電阻數值的 Pin 號
int potGPin = A2; // 定義接收藍色可變電阻數值的 Pin 號
int potBPin = A3; // 定義接收綠色可變電阻數值的 Pin 號

void setup()
{
  pinMode(redPin, OUTPUT); // 設定為輸出模式
  pinMode(bluePin, OUTPUT); // 設定為輸出模式
  pinMode(greenPin, OUTPUT); // 設定為輸出模式
  pinMode(potRPin, INPUT); // 設定為輸入模式
  pinMode(potGPin, INPUT); // 設定為輸入模式
  pinMode(potBPin, INPUT); // 設定為輸入模式
}

void loop()
{
  int potRValue = analogRead(potRPin); // 讀取紅色可變電阻的數值 (0-1023)
  int potGValue = analogRead(potGPin); // 讀取藍色可變電阻的數值 (0-1023)
  int potBValue = analogRead(potBPin); // 讀取綠色可變電阻的數值 (0-1023)

  analogWrite(redPin, map(potRValue, 0, 1023, 0, 255));
  analogWrite(greenPin, map(potGValue, 0, 1023, 0, 255));
  analogWrite(bluePin, map(potBValue, 0, 1023, 0, 255));
  delay(100);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
r1:1
r1:2
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
pot1:GND
pot1:SIG
pot1:VCC
pot2:GND
pot2:SIG
pot2:VCC
pot3:GND
pot3:SIG
pot3:VCC