
In this tutorial we will automatically vary the light intensity of an RGB LED module with the Arduino.
Connect:
Here is the program that automatically varies the light intensity of an RGB LED with the Arduino.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
void setup(){ pinMode(0,OUTPUT); //sets the number 0 digital pin of the Arduino in output modepinMode(0,OUTPUT); //sets the number 1 digital pin of the Arduino in output modepinMode(0,OUTPUT); //sets the number 0 digital pin of the Arduino in output mode pinMode(1,OUTPUT); //sets the number 1 digital pin of the Arduino in output modepinMode(1,OUTPUT); //sets the number 1 digital pin of the Arduino in output modepinMode(1,OUTPUT); //sets the number 1 digital pin of the Arduino in output mode pinMode(2,OUTPUT); //sets the number 2 digital pin of the Arduino in output modepinMode(2,OUTPUT); //sets the number 1 digital pin of the Arduino in output modepinMode(2,OUTPUT); //sets the number 2 digital pin of the Arduino in output mode } void loop(){ //the LED module lights up in red and green digitalWrite(0,HIGH); digitalWrite(1,HIGH); digitalWrite(2,LOW); delay(2000); //lthe LED module lights up in red digitalWrite(0,HIGH); digitalWrite(1,LOW); digitalWrite(2,LOW); delay(2000); //the LED module lights up in red and blue digitalWrite(0,LOW); digitalWrite(1,HIGH); digitalWrite(2,LOW); delay(2000); //the LED module lights up in green digitalWrite(0,HIGH); digitalWrite(1,LOW); digitalWrite(2,HIGH); delay(2000); //the LED module lights up in red ,blue and green digitalWrite(0,HIGH); digitalWrite(1,HIGH); digitalWrite(2,HIGH); delay(2000); } |