FOR statement not executing

The following is a snip from a program for using LEDs as light sensors. The program does not enter the following FOR loop.

Please help.

TIA

digitalWrite(44,LOW);
       pinMode(44,INPUT);
       
       digitalWrite(46,LOW);
       pinMode(46,INPUT);
       
// Count how long it takes the diode to bleed back down to a logic zero
      
      for ( Caunt = 0; Caunt < 60000; Caunt++)
      {
        if ( digitalRead(44)== LOW)
      {
        Value= Caunt;
        break;
      }
          
        if ( digitalRead(46)== LOW)
      {
        Value= Caunt;
        break;
      }

      }

How do you know it never enters it?

Try putting a Serial.print statement in there and see if it hits that.

If you want any more help than that, you're going to have to post the rest of the code so we can see what's going on there.

If Caunt is a signed integer it won't exit on the conditional because a signed integer will never be more than 32767. This is why snippets are bad. We can't see how data types are declared and have to start guessing.

Delta_G:
How do you know it never enters it?

If you want any more help than that, you’re going to have to post the rest of the code…

Thanks guys for the quick response.

I know because I put a lcd.print statement to check. That is why I came to this conclusion

I had summarized the FOR statement so that it is easy to decipher. Anyway here is the full code.

// include the library code.

 #include <LiquidCrystal.h>
 LiquidCrystal lcd(53,51,49,47,45,43);

//variables setup
 
 unsigned int East;
 unsigned int West;
 unsigned int Caunt=0;
 
void setup() { 
 
 _SFR_IO8(0x35) |= 0x10;   // global disable pull up resistors
 
 lcd.begin(16, 4);
}


void loop () {
 

// declare the pins as outputs

     pinMode(42,OUTPUT);
     pinMode(44,OUTPUT); 
   
     pinMode(46,OUTPUT);
     pinMode(48,OUTPUT);
    

// Light up LEDs to discharge junction caps by forward biasing the LED.  cathode = LOW anode = HIGH 
     
     digitalWrite(44,LOW);// Cathode
     digitalWrite(42,HIGH);// Anode
  
     digitalWrite(46,LOW);// Cathode
     digitalWrite(48,HIGH);// Anode

delay(10);     
  
// Charge up LEDs junction caps by reverse biasing the LED.  cathode = HIGH, anode = LOW
 
     
     digitalWrite(44,HIGH);// Cathode
     digitalWrite(42,LOW);// Anode
  
     digitalWrite(46,HIGH);// Cathode
     digitalWrite(48,LOW);// Anode
   
delay(50); 
// Isolate the Cathode end of the diode

      digitalWrite(44,LOW);
      pinMode(44,INPUT);
      
      digitalWrite(46,LOW);
      pinMode(46,INPUT);
      
// Count how long it takes the diode to bleed back down to a logic zero
     
     for ( Caunt = 0; Caunt < 60000; Caunt++)
     {
       if ( digitalRead(44)== LOW)
     {
       East= Caunt;
       break;
     }
         
       if ( digitalRead(46)== LOW)
     {
       West= Caunt;
       break;
     }

     }

// print out the results.
    
  lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("East=");
     lcd.setCursor(6,0);
     lcd.print(East);
  delay(3000); 
     lcd.setCursor(0,1);
     lcd.print("West=");
     lcd.setCursor(6,1);
     lcd.print(0);
     
  delay(3000); 

}
     for ( Caunt = 0; Caunt < 60000; Caunt++)

Count will ALWAYS be less than 60000.

How long do you think it will take that for loop to execute? That is, how long do you have to press a switch?

PaulS:

     for ( Caunt = 0; Caunt < 60000; Caunt++)

Count will ALWAYS be less than 60000.
(…)

I don’t see why. If Caunt is ‘unsigned int’
unsigned int Caunt=0;

can hold values from 0 to 65535, right? Why you said that?

Why you said that?

Because I can't read. I missed the unsigned part.