Please help......
My code works great with my LCD and displays a voltage from 0.00-1.70 with respect to analog input.
I would however like to flash the led the number of times corresponding to the voltage value(the "PPO" Reading) read on analog input........for ex: at .40 volts flash led 4 times, at .50 volts flash led 5 times, at .60 volts flash led 6 times.......... I wrote the following code(highlighted in yellow) and it does flash, but I can not get the flashes to match the analog voltage input. Any help in modifying the code would be great!!!
Thank you!!
// include the library code:
#include <LiquidCrystal.h>
#include <PID_v1.h>
#define aref_voltage 1.72
#define PPO inputReading1*aref_voltage/1024
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, 5,7,2, REVERSE);
// initialize the lcd with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
/****************************************************************
*initiate pins for each led
*****************************************************************/
const int red1 =22;
const int blue1 =0;
const int green1 =0;
const int yellow1 =0;
/****************************************************************/
int nr;
int wait;
/****************************************************************
*initiate pins for sensor inputs 1, 2, 3
*****************************************************************/
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(PPO);
Setpoint = 520;
myPID.SetMode(AUTOMATIC);
analogReference(EXTERNAL); // set external analog Ref for PPO output
/*****************************************************************
*set output assignments for led pins
******************************************************************/
pinMode( red1, OUTPUT);
pinMode( green1, OUTPUT);
pinMode( blue1, 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.
}
/*************************************************************/
[color=yellow]
void blinkRed(int nr, int wait) // number of blinks follwed by a delay
{
{
digitalWrite(red1,LOW);
delay(250);
digitalWrite(red1, HIGH);
delay(250);
}
}
void loop ()
{
if (PPO<.30) blinkRed(3, 0); // flash three red
if (PPO<.40) blinkRed(4, 500); // flash four red
if (PPO<.50) blinkRed(5, 1000); // flash five red
if (PPO<.60) blinkRed(6, 1500); // flash six red
if (PPO<.70) blinkRed(7, 2000); // flash seven red
if (PPO<.80) blinkRed(8, 2500); // flash eight red
if (PPO<.90) blinkRed(9, 3000) ; // flash nine red
if (PPO<1.00) blinkRed(10, 3500) ; // flash ten red
[/color]
/*************************************************************
* turn the output pin on/off based on pid output
**************************************************************/
Input = analogRead(PPO);
myPID.Compute();
analogWrite(7,Output);
/*************************************************************/
lcd.setCursor(0, 1); //sets the cursor to column 0, line 1
//getting the voltage reading from the 02 sensor
inputReading1 = analogRead(sensor1);
// converting that reading to voltage
float voltage1 = inputReading1 * aref_voltage;
voltage1 /= 1024.0;
//print actual voltage to lcd
lcd.print(voltage1, 2);
delay(200);
lcd.setCursor(6, 1); //sets the cursor to column 6, line 1
//getting the voltage reading from the temperature sensor
inputReading2 = analogRead(sensor2);
// converting that reading to voltage
float voltage2 = inputReading2 * aref_voltage;
voltage2 /= 1024.0;
//print actual voltage to lcd
lcd.print(voltage2, 2);
delay(200);
lcd.setCursor(12, 1); //sets the cursor to column 12, line 2
//getting the voltage reading from the temperature sensor
inputReading3 = analogRead(sensor3);
// converting that reading to voltage
float voltage3 = inputReading3 * aref_voltage;
voltage3 /= 1024.0;
//print actual voltage to lcd
lcd.print(voltage3, 2);
delay(200);
}