I have been able to get my code working, however I seem to have one issue I can't seem to overcome, I have three independent outputs driving three independent leds, so each led needs to blink with respect to the current value associated with its output. But the leds only flash one at a time and this needs to happen together.
For example: sensor1 will cause led1 to flash 5 times with output1=.50, at the same time sensor2 may have an output = to .70 in which case led2 will flash 7 times, while sensor3 will cause led3 to flash 7 times with output=.70 also.......
The problem is all three leds need to flash in sync with each other through one complete cycle so if one sensor should fail or its output not equal to the other(as in the example above) this will cause one of the leds to blink short, which will indicate an issue with the associated sensor connect to that output. I have included a copy of my current code. I hope this makes sense.
Thank you
Dave
// include the library code:
#include <LiquidCrystal.h>
#define aref_voltage1 1.72
#define PPO1 inputReading1*aref_voltage/1024
#define PPO2 inputReading2*aref_voltage/1024
#define PPO3 inputReading3*aref_voltage/1024
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the lcd with the numbers of the interface pins
const int red1 =22;
const int blue1 =28;
const int green1 =26;
int nr1; // declare numbers of flashes
const int red2 =30;
const int blue2 =36;
const int green2 =34;
int nr2;
const int red3 =38;
const int blue3 =44;
const int green3 =42;
int nr3;
/*****************************************************************/
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 ()
{
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);
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("PPO1"); // Print a message to the LCD.
lcd.setCursor(6, 0); // set the cursor to column 6, line 0
lcd.print("PPO2"); // Print a message to the LCD
lcd.setCursor(12, 0); // set the cursor to column 12, line 0
lcd.print("PPO3"); // Print a message to the LCD.
}
/****************************************************************/
void blinkGreen1(int nr1) // number of blinks follwed by a delay
{
if( PPO1 <= .50)
for(int i=0; i< nr1; i++)
{
digitalWrite(green1,LOW);
delay(250);
digitalWrite(green1, HIGH);
delay(250);
}
else digitalWrite(green1, HIGH);
}
void blinkBlue1(int nr1) // number of blinks follwed by a delay
{
if( PPO1 > .50 && PPO1 < 1.00)
for(int i=0; i< nr1; i++)
{
digitalWrite(blue1,LOW);
delay(250);
digitalWrite(blue1, HIGH);
delay(250);
}
else digitalWrite(blue1, HIGH);
}
void blinkRed1(int nr1) // number of blinks follwed by a delay
{
if(PPO1 >1.00)
for(int i=0; i< nr1; i++)
{
digitalWrite(red1,LOW);
delay(250);
digitalWrite(red1, HIGH);
delay(250);
}
else digitalWrite(red1, HIGH);
}
void blinkGreen2(int nr2) // number of blinks follwed by a delay
{
if( PPO2 <= .50)
for(int i=0; i< nr2; i++)
{
digitalWrite(green2,LOW);
delay(250);
digitalWrite(green2, HIGH);
delay(250);
}
else digitalWrite(green2, HIGH);
}
void blinkBlue2(int nr2) // number of blinks follwed by a delay
{
if( PPO2 > .50 && PPO2 < 1.00)
for(int i=0; i< nr2; i++)
{
digitalWrite(blue2,LOW);
delay(250);
digitalWrite(blue2, HIGH);
delay(250);
}
else digitalWrite(blue2, HIGH);
}
void blinkRed2(int nr2) // number of blinks follwed by a delay
{
if(PPO2 >1.00)
for(int i=0; i< nr2; i++)
{
digitalWrite(red2,LOW);
delay(250);
digitalWrite(red2, HIGH);
delay(250);
}
else digitalWrite(red2, HIGH);
}
void blinkGreen3(int nr3) // number of blinks follwed by a delay
{
if( PPO3 <= .50)
for(int i=0; i< nr3; i++)
{
digitalWrite(green3,LOW);
delay(250);
digitalWrite(green3, HIGH);
delay(250);
}
else digitalWrite(green3, HIGH);
}
void blinkBlue3(int nr3) // number of blinks follwed by a delay
{
if( PPO3 > .50 && PPO3 < 1.00)
for(int i=0; i< nr3; i++)
{
digitalWrite(blue3,LOW);
delay(250);
digitalWrite(blue3, HIGH);
delay(250);
}
else digitalWrite(blue3, HIGH);
}
void blinkRed3(int nr3) // number of blinks follwed by a delay
{
if(PPO3 >1.00)
for(int i=0; i< nr3; i++)
{
digitalWrite(red3,LOW);
delay(250);
digitalWrite(red3, HIGH);
delay(250);
}
else digitalWrite(red3, HIGH);
}
void loop ()
{
blinkGreen1((int)(PPO1*10)); // flash green1
blinkBlue1((int)(PPO1*10)); // flash blue1
blinkRed1((int)(PPO1*10)); // flash red1
blinkGreen2((int)(PPO2*10)); // flash green2
blinkBlue2((int)(PPO2*10)); // flash blue2
blinkRed2((int)(PPO2*10)); // flash red2
blinkGreen3((int)(PPO3*10)); // flash green3
blinkBlue3((int)(PPO3*10)); // flash blue3
blinkRed3((int)(PPO3*10)); // flash red3
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_voltage1; // 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 O2 sensor
float voltage2 = inputReading2 * aref_voltage2; // 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 O2 sensor
float voltage3 = inputReading3 * aref_voltage3; // converting that reading to voltage
voltage3 /= 1024.0;
lcd.print(voltage3, 2); //print actual voltage to lcd
delay(200);
}