ddami
Published © Apache-2.0

4x RGB-LED Running Light!

4 RGB LED's That blink In A Row Of Colors

AdvancedWork in progress7,388
4x RGB-LED Running Light!

Things used in this project

Hardware components

RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino UNO
Arduino UNO
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1

Schematics

4x_rgb-led_running_light_bb_hb1iN0LHd0.jpg

Code

RGBLEDx4

Arduino
    //The Maker Of This Code Allowed Copying! (With Name Mention)
    int sensorPin = A0;   //PotentioMeter Pin
    int redPin1 = 13;     //The Red Pin Of The 1st LED
    int greenPin1 = 12;   //The Green Pin Of The 1st LED
    int bluePin1 = 11;    //The Blue Pin Of The 1st LED
    int redPin2 = 10;     //The Red Pin Of The 2rd LED
    int greenPin2 = 9;    //The Green Pin Of The 2rd LED
    int bluePin2 = 8;     //The Blue Pin Of The 2rd LED
    int redPin3 = 7;      //The Red Pin Of The 3rd LED
    int greenPin3 = 6;    //The Green Pin Of The 3rd LED
    int bluePin3 = 5;     //The Blue Pin Of The 3rd LED
    int redPin4 = 4;      //The Red Pin Of The 4th LED
    int greenPin4 = 3;    //The Green Pin Of The 4th LED
    int bluePin4 = 2;     //The Blue Pin Of The 4th LED
    int sensorValue = 0;  //The Pin Of The Sensor (No Use To It)
    
    //uncomment this line if using a Common Anode LED
    //#define COMMON_ANODE
     
    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);  
      pinMode(redPin4, OUTPUT);
      pinMode(greenPin4, OUTPUT);
      pinMode(bluePin4, OUTPUT);  
    }
     
    void loop()
    {
      sensorValue = analogRead(sensorPin);
      setColor(255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
      delay(sensorValue);
      sensorValue = analogRead(sensorPin);
      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); 
      analogWrite(redPin4, red3);
      analogWrite(greenPin4, green3);
      analogWrite(bluePin4, blue3); 
       
    }

Credits

ddami

ddami

3 projects • 10 followers

Comments