LED Flickering

Hello Group!

New person to this board and maybe someone can help me solve this unusual LED flickering that is going on with my Arduino/Code. Let me explain my issue first: 1.) 2 photoresistors which control the state of several LEDs. 2.) When Photoresistor1 is not covered Green LED (14) is set to HIGH and when Photoresistor1 is covered Green LED (14) is changed to LOW and Red LED (12) is set to HIGH. 3.) when Photoresistor2 is not covered Green LED (11) is set to HIGH and when Photoresistor2 is covered Green LED (11) is set to low and Red LED (9) is set to HIGH and Yellow LED (13) is set to HIGH. This works, however Green LED (14) starts to flicker very rapidly in a very DIM state. My question is Why is this happening and can someone help me figure it out so that Green LED (14) remains in a LOW state. I have a feeling it has to do with my IF statements as the first IF statement is telling Green LED (14) to remain HIGH while second IF statement is telling Green LED (14) to remain LOW thus creating the 200 millisecond flickering…correct?

int photocellPin       = 19; // Connected to Arduino
int photocellPin2      = 18; // Connected to Aruino

int lowThreshold  = 580;
int lowThreshold2 = 570;

void loop(){

int sensorValue  = analogRead(photocellPin);
int sensorValue2 = analogRead(photocellPin2);
Serial.println(sensorValue);
Serial.println(sensorValue2);
delay(200);

if (sensorValue < lowThreshold){
setRegisterPin(14, LOW);
setRegisterPin(12, HIGH);
writeRegisters();      // MUST BE CALLED TO DISPLAY CHANGES
  // Only call once after the values are set how you need. 
} else {
setRegisterPin(12, LOW);
setRegisterPin(14, HIGH);
writeRegisters();      // MUST BE CALLED TO DISPLAY CHANGES
  // Only call once after the values are set how you need. 
}

if (sensorValue2 < lowThreshold2){
setRegisterPin(13, HIGH);
setRegisterPin(14, LOW);
setRegisterPin(11, LOW);
setRegisterPin(9, HIGH);
writeRegisters();      // MUST BE CALLED TO DISPLAY CHANGES
  // Only call once after the values are set how you need. 
} else {
setRegisterPin(9, LOW);
setRegisterPin(13, LOW);
setRegisterPin(11, HIGH);
writeRegisters();      // MUST BE CALLED TO DISPLAY CHANGES
  // Only call once after the values are set how you need. 
}
}

Your code is missing stuff:

1st the setup function. The serial port is not initialized with serial.begin. And the pinmode of the output pins are not defined.

  1. When I plug this code into my Arduino IDE It does not recognize the functions setRegisterPin and writeRegisters. So you must be using a library that isn’t part of the IDE. So we have no idea how this drives leds or anything.