這次要測試剛買來的全彩LED燈泡測試
網路上的示意圖但紅線(V腳位)不能接5V,要接Ground才能亮 |
//範例用PWM來控制所以用9,10,11三隻PWM腳位,其他非PWM腳位也都可以但只有HIGH or LOW(1 or o) 看使用者應用,因為Arduino UNO腳位不多因此所有腳位都要充分利用。
//或是用Analog腳位A0~A5也是可以的
int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin =9;// select the pin for the green LED
或是數位腳
int redpin = 7; //select the pin for the red LED
int greenpin =2;// select the pin for the green LED
int bluepin =4; // select the pin for the blue LED
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
analogWrite(A3, 255); //255 R 紅 其餘0
analogWrite(A5, 0); //255 G 綠 其餘0
analogWrite(A4, 0); //255 B 藍 其餘0
//黃=R255,G255,B0 橘=228,120,51
delay(1000);
analogWrite(A3, 0); //255 R 紅 其餘0
analogWrite(A5, 255); //255 G 綠 其餘0
analogWrite(A4, 0); //255 B 藍 其餘0
delay(1000);
analogWrite(A3, 255); //255 R 紅 其餘0
analogWrite(A5, 255); //255 G 綠 其餘0
analogWrite(A4, 0); //255 B 藍 其餘0
delay(1000);
digitalWrite(redpin, HIGH); //255 R 紅 其餘0
digitalWrite(greenpin, LOW); //255 G 綠 其餘0
digitalWrite(bluepin, LOW); //255 B 藍 其餘0
/*
for(val=255; val>0; val--)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(10);
}
for(val=0; val<255 p="" val=""> {
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(10);
}
Serial.println(val, DEC);
*/
}255>
沒有留言:
張貼留言