Start a new topic

Problems with while loop

Hi!

 

I have a doubt. I need to use a while loop but the communication is interrupted. I have read that with nextion it can not be used.

 

My previous code is this:

case 1: //Adjust the global brightness 
      matrix.writeDigitRaw(0,0x0); // 
      matrix.writeDigitRaw(1,0x7C); //b 
      matrix.writeDigitRaw(3,0x50); //r 
      matrix.writeDigitRaw(4,0x78); //t 
            
      while (menu_enter == 1){ 
      
      int bright = rotary_process(); 
      
      if (bright == -128){ 
        brightval--; 
        sb++;
      //  testbright = false;
      } 
      if (bright == 64){ 
        brightval++; 
        sb--; 
     //   testbright = false;
      } 
      brightval = constrain (brightval, 0, 15); 
      sb = constrain(sb, 1, 15); 

      if (prev_variable != brightval){
          prev_variable = brightval;
      
            color1 = load_color(c1); 
            color2 = load_color(c2); 
            color3 = load_color(c3); 
            flclr1 = load_color(c4); 
            flclr2 = load_color(c5); 
            
            matrix.setBrightness(brightval); 
            matrix.println(brightval); 
            matrix.writeDisplay(); 
      
           // if (testbright == false){
            testlights(4);
         //  testbright = true;
         //   }
      }


     if (digitalRead(button_pin) == LOW){ 
        delay(250); 
        menu_enter = 2;
        prev_variable = 0; 
        clearStrip(); 
        strip.show(); 
        for(int i=0; i<NUMPIXELS+1; i++) { 
          strip.setPixelColor(i, color1); 
          strip.show(); 
          delay(15); 
          strip.setPixelColor(i, strip.Color(0, 0, 0)); 
          strip.show(); 
        }         
      }      
      }     
    break; 

 And the new is:

switch(setMenu_type){
    
    case 1:

      if(set_button == 1){
        brightval++; 
        sb--; 
      }
      
       if (set_button == 2){
        
        brightval--; 
         sb++;   
         
      }
       brightval = constrain (brightval, 1, 15); 
      sb = constrain(sb, 1, 15);
       if (prev_variable != brightval){
          prev_variable = brightval;
      
            color1 = load_color(c1); 
            color2 = load_color(c2); 
            color3 = load_color(c3); 
            flclr1 = load_color(c4); 
            flclr2 = load_color(c5); 
            
           Serial2.print("valor_brillo.val="); 
           Serial2.print(brightval); 
           ff(); 

            testlights(4);

      }    

 I need to create a loop in the menu so that the led's light up.

 

How could I do it?

 

Thank you very much


What is the Nextion portion of the question?

If I use a while loop, nextion is blocked. How can I solve that?

A programmer choses to use a code block for a reason.


            examples of block of code include

      do-while, for, if-then-else, repeat-until, etc.


Most likely, what the block needs to process has a need

     and therefore, such priority to do in the fashion

           the programmer has chosen to do it in


If Nextion needs to be within the code block then the

     programmer needs to include read()s and the

    decision processing on what bytes is read() in


This deviates from Arduino method of processing of RX buffers

which is handled at the end of loop().  So if Arduino isn't to be

what handles the buffers, then the programmer must then handle

 - see HardwareSerial class source

From your code, Nextion is blocked only because

 - you chose to make the other more important


But I am not really seeing this as a Nextion question

  a status valor_brillo.val=  doesn't make this Nextion

  your code issue is Arduino and other items connected

Login or Signup to post a comment