How to use Blink with no delay......?

Could someone please help, I would like to use the blink but its giving me some unwanted results. I have tried using the sample function "Blink withoutDelay" but have come up unsuccessful. Could you please let me know if the "Blink withoutDelay" can be used on the following code.

Thank you!!!!

 // include the library code:
     #include <LiquidCrystal.h>
     #include <PID_v1.h>
     #define aref_voltage 1.72
     #define PPO1 inputReading1*aref_voltage/1024
     #define PPO2 inputReading2*aref_voltage/1024
     #define PPO3 inputReading3*aref_voltage/1024
           
      double Setpoint, Input, Output; //Define Variables we'll be connecting to     
      PID myPID(&Input, &Output, &Setpoint, 5,7,2, REVERSE); //Specify the links and initial tuning parameters
            
      LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the lcd with the numbers of the interface pins
      

      const int red1      =28;
      const int blue1     =22; 
      const int green1    =24;
      const int yellow1   =26;
            int nr; // declare numbers of flashes

  

      const int red2      =36;
      const int blue2     =30; 
      const int green2    =32;
      const int yellow2   =34;
            


      const int red3      =44;
      const int blue3     =38; 
      const int green3    =40;
      const int yellow3   =42;
            

           
      const int sensor1 = A0;  // the analog pin the 02 Sensor Vout pin is connected to
            int inputReading1; //declare a variable 
      
                         
      const int sensor2 = A1;  // the analog pin the 02 Sensor Vout pin is connected to  
            int inputReading2; // declare a variable   
               
      
      const int sensor3 = A2;  // the analog pin the 02 sensor Vout pin is connected to
            int inputReading3; // declare a variable      


    void setup () 
        
    {

       Input = analogRead(PPO1); // initialize PPO variable for PID function
       Setpoint = 520;          // initialize setpoint variable for PID function 
       myPID.SetMode(AUTOMATIC); // configure PID for auto control
  
       analogReference(EXTERNAL); // set external analog Ref for PPO output
           
  
       pinMode( red1, OUTPUT);
       pinMode( green1, OUTPUT);
       pinMode( blue1, OUTPUT);     


     
       pinMode( red2, OUTPUT);
       pinMode( green2, OUTPUT);
       pinMode( blue2, OUTPUT);     



    
       pinMode( red3, OUTPUT);
       pinMode( green3, OUTPUT);
       pinMode( blue3, OUTPUT);     

     
            
/***************************************************************
*set up the LCD's number of columns and rows:
****************************************************************/ 
      lcd.begin(20, 4);
  
      lcd.setCursor(0, 0);//where to start cursor
      lcd.print("PINA SYSYTEMS       ");//print message
      lcd.print("SOFTWARE VERSION 1.0");//print message
      delay(2000);
      lcd.clear();  
      
      lcd.setCursor(0, 0); // set the cursor to column 0, line 0
      lcd.print("PP1");  // Print a message to the LCD.
  
      lcd.setCursor(6, 0); // set the cursor to column 6, line 0
      lcd.print("PP2"); // Print a message to the LCD
  
      lcd.setCursor(12, 0); // set the cursor to column 12, line 0
      lcd.print("PP3");  // Print a message to the LCD.
    }
/****************************************************************/



 
      void blinkRGB1(int nr) // number of blinks follwed by a delay 
       {
         for(int i=0; i< nr; i++)
         if( PPO1 <= .50) 
          {
            digitalWrite(green1,LOW); 
            delay(250); 
            digitalWrite(green1, HIGH);
            delay(250); 
          }
            else digitalWrite(green1, HIGH);        
       
               
         for(int i=6; i< nr; i++)
         if( PPO1 > .50 && PPO1 < 1.00) 
          {
            digitalWrite(blue1,LOW); 
            delay(250); 
            digitalWrite(blue1, HIGH);
            delay(250); 
          }
            else digitalWrite(blue1, HIGH);        
       
        
         for(int i=11; i< nr; i++)
         if(PPO1 >1.00)   
          {
            digitalWrite(red1,LOW); 
             delay(250); 
            digitalWrite(red1, HIGH);
            delay(250); 
          }
            else digitalWrite(red1, HIGH);           
       }
      


       void blinkRGB2(int nr) // number of blinks follwed by a delay 
       {
         for(int i=1; i< nr; i++)
         if( PPO2 <= .50) 
          {
            digitalWrite(green2,LOW); 
            delay(250); 
            digitalWrite(green2, HIGH);
            delay(250); 
          }
            else digitalWrite(green2, HIGH);        
       
               
         for(int i=5; i< nr; i++)
         if( PPO2 > .50 && PPO2 < 1.00) 
          {
            digitalWrite(blue2,LOW); 
            delay(250); 
            digitalWrite(blue2, HIGH);
            delay(250); 
          }
            else digitalWrite(blue2, HIGH);        
       
        
         for(int i=10; i< nr; i++)
         if(PPO2 >1.00)   
          {
            digitalWrite(red2,LOW); 
             delay(250); 
            digitalWrite(red2, HIGH);
            delay(250); 
          }
            else digitalWrite(red2, HIGH);           
       }

   
            
       void blinkRGB3(int nr) // number of blinks follwed by a delay 
       {
         for(int i=1; i< nr; i++)
         if( PPO3 <= .50) 
          {
            digitalWrite(green3,LOW); 
            delay(250); 
            digitalWrite(green3, HIGH);
            delay(250); 
          }
            else digitalWrite(green3, HIGH);        
       
               
         for(int i=5; i< nr; i++)
         if( PPO3 > .50 && PPO3 < 1.00) 
          {
            digitalWrite(blue3,LOW); 
            delay(250); 
            digitalWrite(blue3, HIGH);
            delay(250); 
          }
            else digitalWrite(blue3, HIGH);        
       
        
         for(int i=10; i< nr; i++)
         if(PPO3 >1.00)   
          {
            digitalWrite(red3,LOW); 
             delay(250); 
            digitalWrite(red3, HIGH);
            delay(250); 
          }
            else digitalWrite(red3, HIGH);           
       }
      

    
     void loop () 
    
       {
          blinkRGB1((int)(PPO1*10)); // flash RGB1  
          blinkRGB2((int)(PPO2*10)); // flash RGB2
          blinkRGB3((int)(PPO3*10)); // flash RGB3
           
          
                   
/**********************************************************************
* turn the output pin on/off based on pid output
***********************************************************************/
        Input = analogRead(PPO1); // PID analog input for PPO
        myPID.Compute(); // computing the out for setpoint control
        analogWrite(7,Output); // the output to fire O2 solenoid
/**********************************************************************/
  
   
       
        lcd.setCursor(0, 1); //sets the cursor to column 0, line 1    
        inputReading1 = analogRead(sensor1); //getting the voltage reading from the 02 sensor    
        float voltage1 = inputReading1 * aref_voltage; // converting that reading to voltage 
        voltage1 /= 1024.0;    
        lcd.print(voltage1, 2);//print actual voltage to lcd    
        delay(200);
    

        lcd.setCursor(6, 1); //sets the cursor to column 6, line 1     
        inputReading2 = analogRead(sensor2); //getting the voltage reading from the temperature sensor    
        float voltage2 = inputReading2 * aref_voltage; // converting that reading to voltage
        voltage2 /= 1024.0; 
        lcd.print(voltage2, 2);  //print actual voltage to lcd
        delay(200);     
  
  
        lcd.setCursor(12, 1); //sets the cursor to column 12, line 2    
        inputReading3 = analogRead(sensor3); //getting the voltage reading from the temperature sensor    
        float voltage3 = inputReading3 * aref_voltage; // converting that reading to voltage 
        voltage3 /= 1024.0; 
        lcd.print(voltage3, 2);  //print actual voltage to lcd
        delay(200);
 
      }

What about the Blink Without Delay example did you not understand? The concept is pretty simple.

You can cause something to happen at a specific time in the future in two ways.

Note what time the preceding event occurs. Periodically, see if enough time has elapsed. If so, do the next event.

Or, you can, when the first event occurs, set a timer, and stand around doing nothing until the timer goes off. Then, perform the second event.

The Blink Without Delay example shows how to do it the first way. The delay() call that you have now is the second way.

As you have probably imagined, it will require a major re-write of your code to get rid of all the delays.

OF course, before you bother with that, you REALLY need to fix your code so that it does not read from variable pin numbers.

PaulS:
What about the Blink Without Delay example did you not understand? The concept is pretty simple.

You can cause something to happen at a specific time in the future in two ways.

Note what time the preceding event occurs. Periodically, see if enough time has elapsed. If so, do the next event.

Or, you can, when the first event occurs, set a timer, and stand around doing nothing until the timer goes off. Then, perform the second event.

The Blink Without Delay example shows how to do it the first way. The delay() call that you have now is the second way.

As you have probably imagined, it will require a major re-write of your code to get rid of all the delays.

OF course, before you bother with that, you REALLY need to fix your code so that it does not read from variable pin numbers.

I'm not to clear on the variable pin numbers?......could you please give a small example?
I thought there might be a major rewrite in my future, is their any way you could provide a small sample of what a section of the code should look like? This will help me break apart the ins and outs and understand it better.

Thank you!!!

I'm not to clear on the variable pin numbers?......could you please give a small example?

Input = analogRead(PPO1); // initialize PPO variable for PID function

where #define PPO1 inputReading1*aref_voltage/1024

I'm not to clear on the variable pin numbers?......could you please give a small example?

       Input = analogRead(PPO1); // initialize PPO variable for PID function

What pin are you reading from? PPO1 is declared like so:

     #define PPO1 inputReading1*aref_voltage/1024

So, when the pre-processor does its thing, the first line I showed becomes:

       Input = analogRead(inputReading1*aref_voltage/1024); // initialize PPO variable for PID function

which really does not make sense.

inputReading1 is not explicitly initialized, so the compiler sets it to 0, which means that the reading will occur on analog pin 0. But, what's that statement really meant to do?

I am guessing that you want to use sensor readings to make PPO values.

Using parts of your code I think you want 3 versions of this;

inputReading1 = analogRead(sensor1);
        PPO1 = (inputReading1 * aref_voltage / 1024);

cyclegadget:
I am guessing that you want to use sensor readings to make PPO values.

Using parts of your code I think you want 3 versions of this;

inputReading1 = analogRead(sensor1);

PPO1 = (inputReading1 * aref_voltage / 1024);

Very good!!!!! You hit the nail on the head!!!!!
That's what I'm doing....I'm using "(inputReading1 * aref_voltage / 1024)" to calculate the actual PPO value based on the "0-1023" value.
To print this value to the LCD.

Example: (inputReading1(555) * aref_voltage(1.72) / 1024) = .93 volts

cyclegadget:
I am guessing that you want to use sensor readings to make PPO values.

Using parts of your code I think you want 3 versions of this;

inputReading1 = analogRead(sensor1);

PPO1 = (inputReading1 * aref_voltage / 1024);

This is great thank you!!!!
Where do you suggest I try inserting this?.....PPO1 = (inputReading1 * aref_voltage / 1024)

Where do you suggest I try inserting this?

]:smiley:

cyclegadget:
I am guessing that you want to use sensor readings to make PPO values.

Using parts of your code I think you want 3 versions of this;

inputReading1 = analogRead(sensor1);

PPO1 = (inputReading1 * aref_voltage / 1024);

I'm using the PPO values of 0-1.72 to flash the RGB's three colors with respect to a specific range of voltage.
And display this voltage via the LCD screen, I'm also working on using a Smart-GPU color display from Vizio, but I have not been able to get that working yet.

Grumpy_Mike:

Where do you suggest I try inserting this?

]:smiley:

YA...YA...YA....YA....I guess I set myself up for this one.
Someone has their mind in the gutter....HAHAHAHHAHAHAHAHA

concretefreak:

cyclegadget:
I am guessing that you want to use sensor readings to make PPO values.

Using parts of your code I think you want 3 versions of this;

inputReading1 = analogRead(sensor1);

PPO1 = (inputReading1 * aref_voltage / 1024);

I'm using the PPO values of 0-1.72 to flash the RGB's three colors with respect to a specific range of voltage.
And display this voltage via the LCD screen, I'm also working on using a Smart-GPU color display from Vizio, but I have not been able to get that working yet.

Will this suggestion allow me to omit the delay function?

I guess I set myself up for this one.

You did.

No it will not allow you to remove the delay it will just make your code work. Replace the two lines for the wrong one line you had before.

Grumpy_Mike:

I guess I set myself up for this one.

You did.

No it will not allow you to remove the delay it will just make your code work. Replace the two lines for the wrong one line you had before.

Perfect!! Thank you!!

Grumpy_Mike:

I guess I set myself up for this one.

You did.

No it will not allow you to remove the delay it will just make your code work. Replace the two lines for the wrong one line you had before.

I did try to replace with those lines and get rid of the "#define" lines, but my leds stop flashing......hhhhhhmmmmm
When I put the "#define" lines back the leds flash accordingly....... :~
I not quite sure what I did wrong, could you please specify the lines to be removed and replaced.

Thank you again!!

The fact that you don't seem to think it works when you remove that error means you have something else wrong. Did you write this code yourself?

Grumpy_Mike:
The fact that you don't seem to think it works when you remove that error means you have something else wrong. Did you write this code yourself?

The code can't be that far wrong cause it works great with the sensor,it displays the correct voltage output of the sensor on the LCD display, flashes the leds a number of times with respect to the range of the sensors voltage I've specified, and cycles through with no errors. The only thing I would like do is replace the delay function with "Blink withoutDelay", this needs to be changed because when the voltage of the sensor various, there's a delay in the response time it takes for the LCD display to update the current voltage.

concretefreak:

Grumpy_Mike:
The fact that you don't seem to think it works when you remove that error means you have something else wrong. Did you write this code yourself?

The code can't be that far wrong cause it works great with the sensor,it displays the correct voltage output of the sensor on the LCD display, flashes the leds a number of times with respect to the range of the sensors voltage I've specified, and cycles through with no errors. The only thing I would like do is replace the delay function with "Blink withoutDelay", this needs to be changed because when the voltage of the sensor various, there's a delay in the response time it takes for the LCD display to update the current voltage.

I know I sounds nuts but I think that's what's happening?

Add a Serial.begin() statement to setup(). Add Serial.print() and Serial.println() statements to setup() and loop(). Figure out for yourself what the output of various functions is.

The only thing I would like do is replace the delay function with "Blink withoutDelay

That is no only, it is a big task because you left it late in the development process to do that.
You need to implement a state machine, that is where each delay is a diffrent state and you scan the things you need to do next to see if it is time to do them. Given the track record of getting one line replaced this might just be the longest thread in the foroum's history.
If I were you I would start over.
Try extending the blink without delay sketch to have a diffrent on and off time. Then to flashing one LED out of three in turn.
Build up to what you want to do. It is not a magic bulet that you replace in the same line of code as the delay, it is a whole new way of thinking about how code should run.