Can't check digital input in while loop

Hello. I'm new to the forum.

I am trying to check a digital input within a while loop. It just gets ignored, it seems.

I am communicating wirelessly between two Arduino Unos using 433MHz receiver/transmitter and HT12D decoder and HT12E encoder respectively. There are 4 data bits for passing data back and forth. It's working splendidly except for this one last hurdle of one Uno being able to stop the other's LED cycle.

Here is the function in question below. I'd like to include an image of the schematic, in case anyone's interested but don't see a way to do it.

void turn_on_display() {
int period = 2000;
unsigned long time_now = 0;

 if (buzzer_ID_read_0 == brain_ID_sent_0 && buzzer_ID_read_1 == brain_ID_sent_1 &&
      buzzer_ID_read_2 == brain_ID_sent_2 && buzzer_ID_read_0 == brain_ID_sent_0) 
      {
  //compare IDs of original requestin box with answering box
  buzzer_ID_read_0 = digitalRead(pin2);
  buzzer_ID_read_1 = digitalRead(pin3);
  buzzer_ID_read_2 = digitalRead(pin4);

  brain_ID_sent_0 = digitalRead(pin10);
  brain_ID_sent_1 = digitalRead(pin11);
  brain_ID_sent_2 = digitalRead(pin12);

//turn off all pixels, white
   for( int i = 0; i < numPixels; i++ )
   {
    strip.setPixelColor(i, r, g, b);
    strip.show();// show all pixels   
   }
 
    //keep leds on for period
    time_now = millis();
   while(millis() < time_now + period)
    {
      //check for led shutoff signal
      if(digitalRead(led_on_off_bit) == 0)
      {
        strip.clear();
        strip.show();
        break;// exit loop
      }
    }
 
   }


//clear variables
buzzer_ID_read_0 = 0;
buzzer_ID_read_1 = 0;
buzzer_ID_read_2 = 0;

brain_ID_sent_0 = 0;
brain_ID_sent_1 = 0;
brain_ID_sent_2 = 0;


 strip.clear();
 strip.show();
delay(5000);//delay for locking out other buzzers 


} 

How is the millis() time ever going to be different from the time_now variable?
Please post all your code because you probably are making more mistakes in the code we can't see.

Hi. The time_now is assigned outside the loop so doesn't change inside the loop, if I"m understanding your point correctly.

I think the test of millis() is fine, but what makes the led_on_off_bit go low, and is it really happening? Is it set up as an input that can be tested?

Yes, if you read my description of the project, it is a signal send wirelessly by another Uno. It does indeed go low, checked on my o'scope.

You may be on to something! I manually grounded the pin with a jumper wire and it did respond. I think, only having a 2 channel o'scope, I wasn't looking at the whole 'timing diagram' and although it was low it must have been outside the window of time it was reading. Time to get a 4 channel scope or logic alalyzer! Thanks.

Post ALL your code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.