ok i found the void setup error…
not sure what you mean by red and green functions defined in the loop…?
#include <LiquidCrystal.h>
// number of analog samples to take per reading, per channel
#define NUM_SAMPLES 10
// voltage divider calibration values
#define DIV_1 11.255
#define DIV_2 11.255
// ADC reference voltage / calibration value
#define V_REF 4.991
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sum[4] = {0}; // sums of samples taken
unsigned char sample_count = 0; // current sample number
float voltage[4] = {0.0}; // calculated voltages
char l_cnt = 0; // used in 'for' loops
const int lowLimit = 80;
const int highLimit = 100;
int volt;
void setup()
{
lcd.begin(16, 2);
pinMode (2, INPUT); // raw voltage input
pinMode (3, INPUT); // raw voltage output
Serial.begin(9600); // set up Serial library at 9600 bps, monitor
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
// take a number of analog samples and add them up
while (sample_count < NUM_SAMPLES)
{
// sample each channel A2 to A5
for (l_cnt = 0; l_cnt < 4; l_cnt++)
{
sum[l_cnt] += analogRead(A2 + l_cnt);
}
sample_count++;
delay(50);
}
// calculate the voltage for each channel
for (l_cnt = 0; l_cnt < 4; l_cnt++)
{
voltage[l_cnt] = ((float)sum[l_cnt] / (float)NUM_SAMPLES * V_REF) / 1024.0;
}
// display voltages on LCD
// each voltage is multiplied by the resistor network
// division factor to calculate the actual voltage
// voltage 1 - A (pin A2)
lcd.setCursor(0, 0);
lcd.print("IN ");
lcd.print(voltage[0] * DIV_1, 1);
lcd.print("V ");
// voltage 2 - B (pin A3)
lcd.setCursor(8, 0);
lcd.print("OUT ");
lcd.print(voltage[1] * DIV_2, 1);
lcd.print("V ");
// voltge 3 - C (pin A4)
lcd.setCursor(0, 1);
lcd.print("STATUS: ");
// voltage 4 - D (pin A5)
lcd.setCursor(12, 1);
lcd.print("CAL!");
// reset count and sums
sample_count = 0;
for (l_cnt = 0; l_cnt < 4; l_cnt++)
{
sum[l_cnt] = 0;
}
//INDICATOR LIGHTS SETUPS
int sensorValue = analogRead(A3); // reads voltage from A3, output
Serial.println(sensorValue); // print out the value you read:
delay(5); // refresh rate
volt = analogRead(3);
if(volt<lowLimit)//voltage below lower limit
red();
else if(volt<=highLimit)//now we know that voltage is between low and high
green();
else//now we know that voltage is above high
red();
#include <LiquidCrystal.h>
// number of analog samples to take per reading, per channel
#define NUM_SAMPLES 10
// voltage divider calibration values
#define DIV_1 11.255
#define DIV_2 11.255
// ADC reference voltage / calibration value
#define V_REF 4.991
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sum[4] = {0}; // sums of samples taken
unsigned char sample_count = 0; // current sample number
float voltage[4] = {0.0}; // calculated voltages
char l_cnt = 0; // used in 'for' loops
const int lowLimit = 80;
const int highLimit = 100;
int volt;
void setup()
{
lcd.begin(16, 2);
pinMode (2, INPUT); // raw voltage input
pinMode (3, INPUT); // raw voltage output
Serial.begin(9600); // set up Serial library at 9600 bps, monitor
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
void loop()
{
// take a number of analog samples and add them up
while (sample_count < NUM_SAMPLES)
{
// sample each channel A2 to A5
for (l_cnt = 0; l_cnt < 4; l_cnt++)
{
sum[l_cnt] += analogRead(A2 + l_cnt);
}
sample_count++;
delay(50);
}
// calculate the voltage for each channel
for (l_cnt = 0; l_cnt < 4; l_cnt++)
{
voltage[l_cnt] = ((float)sum[l_cnt] / (float)NUM_SAMPLES * V_REF) / 1024.0;
}
// display voltages on LCD
// each voltage is multiplied by the resistor network
// division factor to calculate the actual voltage
// voltage 1 - A (pin A2)
lcd.setCursor(0, 0);
lcd.print("IN ");
lcd.print(voltage[0] * DIV_1, 1);
lcd.print("V ");
// voltage 2 - B (pin A3)
lcd.setCursor(8, 0);
lcd.print("OUT ");
lcd.print(voltage[1] * DIV_2, 1);
lcd.print("V ");
// voltge 3 - C (pin A4)
lcd.setCursor(0, 1);
lcd.print("STATUS: ");
// voltage 4 - D (pin A5)
lcd.setCursor(12, 1);
lcd.print("CAL!");
// reset count and sums
sample_count = 0;
for (l_cnt = 0; l_cnt < 4; l_cnt++)
{
sum[l_cnt] = 0;
}
//INDICATOR LIGHTS SETUPS
int sensorValue = analogRead(A3); // reads voltage from A3, output
Serial.println(sensorValue); // print out the value you read:
delay(5); // refresh rate
volt = analogRead(3);
if(volt<lowLimit)//voltage below lower limit
red();
else if(volt<=highLimit)//now we know that voltage is between low and high
green();
else//now we know that voltage is above high
red();
void green(){
digitalWrite(8, 0); //red light off
digitalWrite(9, 1); //green light on
} //gren()
void red(){
digitalWrite(8, 1); //red light on
digitalWrite(9, 0); //green light off
} //red()
}
}