4 Display colors with RGB LED
- int led = 13;
- int led1 = 12;
- int led2 = 11;
- // the setup routine runs once when you press reset:
- void setup() {
- // initialize the digital pin as an output.
- pinMode(led, OUTPUT);
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- }
- void loop() {
- digitalWrite(led2, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led, HIGH);
- delay(500);
- digitalWrite(led, LOW);
- digitalWrite(led1, HIGH);
- delay(500);
- digitalWrite(led1, LOW);
- digitalWrite(led2, HIGH);
- delay(500);
- digitalWrite(led2 , LOW);
- delay(500);
NOTE : NIẾU BẠN MUỐN SÁNG CÁC MÀU KHÁC NHAU :
analogWrite(11,i);
analogWrite(12,i);
analogWrite(13,i);
Trong đó i là giá trị bạn muốn gắn.