Make RGB LED Light up brighter?

  arduino, arduino-uno, c++, rgb

I’ve been trying to make a traffic light simulator but am having trouble with making one RGB light up brightly (in the code it’s referred to with (colour)Pin2). The first light works perfectly but the RGB on the left isn’t working correctly. I succeeded in making it bright when the light is white, but when I try to make it yellow the light is so dim I can barely see it. It’s wired correctly so I think there may be an error in the code. Here’s the link to the project if anyone needs it https://www.tinkercad.com/things/g0UkhvSKylW-copy-of-traffic-light-with-pedestrian-crossing

(also sorry for the messy code, I’m not that used to arduinos yet so I know the code isn’t great)

int redLight = 13;
int yellowLight = 12;
int greenLight = 11;
int redLight2 = 10;
int yellowLight2 = 9;
int greenLight2 = 8;
int redPin = 7;
int bluePin = 6;
int greenPin = 5;
int redPin2 = 4;
int bluePin2 = 3;
int greenPin2 = 2;

void setup() {
  pinMode(redLight, OUTPUT);
  pinMode(yellowLight, OUTPUT);
  pinMode(greenLight, OUTPUT);
  pinMode(redLight2, OUTPUT);
  pinMode(yellowLight2, OUTPUT);
  pinMode(greenLight2, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(greenPin, OUTPUT);
}

void loop() {
  //Note: leftmost traffic light is used for refrence
  //all other lights are based on each others timing
  while(digitalRead(redLight) ==HIGH){
    redLightOn();
    break;
  }
  while(digitalRead(greenLight) == HIGH){
   //pedestrian light is white
    digitalWrite(redPin, 255);
    digitalWrite(greenPin, 255);
    digitalWrite(bluePin, 255);
    //pedestrian light is off
    digitalWrite(redLight2, HIGH);
    delay(6000);
    digitalWrite(bluePin, 0);//make sure to turn blue pin off!
    digitalWrite(redPin, 255);
    digitalWrite(greenPin, 40);
    delay(1000);
    digitalWrite(redPin, 0);
    digitalWrite(greenPin, 0);
    delay(500);
    digitalWrite(redPin, 255);
    digitalWrite(greenPin, 40);
    delay(1000);
    digitalWrite(redPin, 0);
    digitalWrite(greenPin, 0);
    delay(500);
    digitalWrite(redPin, 255);
    digitalWrite(greenPin, 40);
    delay(1000);
    digitalWrite(greenLight, LOW);
    digitalWrite(redPin, 0);
    digitalWrite(greenPin, 0);
    digitalWrite(bluePin, 0);
    digitalWrite(yellowLight, HIGH);
    //pedestrial light flashing
    digitalWrite(redPin, 255);
    digitalWrite(greenPin, 40);

  delay(5000);
    //yellow light changes to red
    digitalWrite(yellowLight, LOW);
    digitalWrite(redLight, HIGH);
  }

//Initial starting light: starts off red
  digitalWrite(redLight, HIGH);
}
//create an initial red light function
void redLightOn(){
    digitalWrite(redLight2, LOW);
    digitalWrite(greenLight2, HIGH);
    digitalWrite(redPin2, 255);
    digitalWrite(greenPin2, 255);
    digitalWrite(bluePin2, 255);
    //pedestrian light on white
    digitalWrite(redPin, 255);
    digitalWrite(greenPin, 40);
    //pedestrian light is off
    delay(6000);
    digitalWrite(bluePin2, 0);//make sure to turn blue pin off!
    digitalWrite(redPin2, 255);
    digitalWrite(greenPin2, 255);
    delay(1000);
    digitalWrite(redPin2, 0);
    digitalWrite(greenPin2, 0);
    delay(500);
    pYellow();
    delay(1000);
    digitalWrite(redPin2, 0);
    digitalWrite(greenPin2, 0);
    delay(500);
    pYellow();
    delay(1000);
    digitalWrite(greenLight, LOW);
    //digitalWrite(redPin, 0);
    //digitalWrite(greenPin, 0);
    //digitalWrite(bluePin, 0);
    digitalWrite(greenLight, LOW);

    //pedestrial light off
  
    digitalWrite(greenLight2, LOW);
    digitalWrite(yellowLight2, HIGH);
    delay(5000);
    digitalWrite(yellowLight2, LOW);
    digitalWrite(redLight, LOW);
    digitalWrite(greenLight, HIGH);
}

void pYellow(){
    digitalWrite(redPin2, 255);
    digitalWrite(greenPin2, 40);
}

Source: Windows Questions C++

LEAVE A COMMENT