RGB LED Running Light
int sensorPin = A0 ; int redPin1 = 13 ; int greenPin1 = 12 ; int bluePin1 = 11 ; int redPin2 = 7 ; int greenPin2 = 6 ; int bluePin2 = 5 ; int redPin3 = 3 ; int greenPin3 = 2 ; int bluePin3 = 1 ; int sensorValue = 0 ;
void setup () { pinMode ( redPin1 , OUTPUT ); pinMode ( greenPin1 , OUTPUT ); pinMode ( bluePin1 , OUTPUT ); pinMode ( redPin2 , OUTPUT ); pinMode ( greenPin2 , OUTPUT ); pinMode ( bluePin2 , OUTPUT ); pinMode ( redPin3 , OUTPUT ); pinMode ( greenPin3 , OUTPUT ); pinMode ( bluePin3 , OUTPUT ); }
void loop () { sensorValue = analogRead ( sensorPin ); setColor ( 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogReadsensorPin ); setColor ( 255 , 0 , 0 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 135 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 135 , 0 , 255 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 135 , 0 , 255 , 127 , 0 , 255 , 127 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 135 , 0 , 255 , 127 , 0 , 255 , 127 , 0 , 255 ,
127 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 255 , 0 , 255 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 255 , 0 , 255 , 255 , 0 , 255 , 255 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 255 , 255 , 0 , 255 , 255 , 0 , 255 , 255 , 0 , 255 ,
255 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 255 , 0 , 0 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 0 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 255 , 0 , 0 , 255 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 75 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 75 , 0 , 130 , 75 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 75 , 0 , 130 , 75 , 0 , 130 , 75 , 0 , 130 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 75 , 0 , 130 , 75 , 0 , 130 , 75 , 0 , 130 , 75 , 0 , 130 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 148 , 0 , 211 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 148 , 0 , 211 , 148 , 0 , 211 , 0 , 0 , 0 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 148 , 0 , 211 , 148 , 0 , 211 , 148 , 0 , 211 , 0 , 0 , 0 ); delay ( sensorValue ); sensorValue = analogRead ( sensorPin ); setColor ( 148 , 0 , 211 , 148 , 0 , 211 , 148 , 0 , 211 , 148 ,
0 , 211 ); delay ( sensorValue ); }
void setColor ( int red , int green , int blue , int red1 , int green1 , int blue1 , int red2 , int green2 , int blue2 , int red3 , int green3 , int blue3 ) { # ifdef COMMON _ ANODE red = 255 - red ; green = 255 - green ; blue = 255 - blue ; red1 = 255 - red1 ; green1 = 255 - green1 ; blue1 = 255 - blue1 red2 = 255 - red2 ; green2 = 255 - green2 ; blue2 = 255 - blue2 ; red3 = 255 - red3 ; green3 = 255 - green3 ; blue3 = 255 - blue3 ; # endif analogWrite ( redPin1 , red ); analogWrite ( greenPin1 , green ); analogWrite ( bluePin1 , blue ); analogWrite ( redPin2 , red1 ); analogWrite ( greenPin2 , green1 ); analogWrite ( bluePin2 , blue1 ); analogWrite ( redPin3 , red2 ); analogWrite ( greenPin3 , green2 ); analogWrite ( bluePin3 , blue2 ); }
11 Exploring Arduino basics