程式碼
analogWrite(pin,v) //電壓0~5V,0~255表示
控制燈的強弱調出自己的顏色。可以利用在三原色的實驗。
底下是自己亂寫的(反正不要短路就好了,勇敢的亂寫)
int redPin = 9; // R petal on RGB LED module connected to digital pin 9
int greenPin = 10; // G petal on RGB LED module connected to digital pin 10
int bluePin = 11; // B petal on RGB LED module connected to digital pin 11
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
}
void loop() // run over and over again
{
analogWrite(redPin, 124);//紅
delay(500);
analogWrite(redPin, 0);//關燈
delay(500);
analogWrite(greenPin,50);//橙
analogWrite(redPin, 255);
delay(500);
analogWrite(greenPin, 0);
analogWrite(redPin, 0);
delay(500);
analogWrite(greenPin, 100);//黃
analogWrite(redPin, 255);
delay(500);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
delay(500);
analogWrite(greenPin, 125); //綠
delay(500);
analogWrite(greenPin, 0);
delay(500);
analogWrite(bluePin, 125);//藍
delay(500);
analogWrite(bluePin, 0);
delay(500);
analogWrite(redPin, 150);//靛
analogWrite(bluePin, 80);
delay(500);
analogWrite(redPin, 0);
analogWrite(bluePin, 0);
delay(500);
analogWrite(redPin, 64);//紫
analogWrite(bluePin, 255);
delay(500);
analogWrite(redPin, 0);
analogWrite(bluePin, 0);
delay(500);
analogWrite(greenPin,125);//白
analogWrite(redPin,125);
analogWrite(bluePin,125);
delay(500);
analogWrite(greenPin, 0);
analogWrite(redPin, 0);
analogWrite(bluePin, 0);
delay(500);
}
沒有留言:
張貼留言