thanks for your input Doc, if i understand you correctly, your actually talking about turning off the lcd?
this wouldn't fit with the overall view of how i what this piece of code to fit into the overall project that i have in mind, for example i would like to have my main code with this code sat in the background and only appearing for a set amount of time when the batt volt is below the threshold and then returning to the main display, run by the main code
i have got the timer working, but lcd.clear() only half clears the display, unlike when the voltage returns above the threshold when the display clears completely
any ideas
code as it is now: -
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
boolean lowbatt = false;
unsigned long Timer; //ALWAYS use unsigned long for timers, not int
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 13; // pin that the LED is attached to
const int threshold = 3; // an arbitrary threshold level that's in the range of the analog input
void setup() {
pinMode(ledPin, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// declare pin 9 to be an output:
pinMode(6, OUTPUT);
analogWrite(6, 90);//contrast
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// if the analog value is low enough:
if (voltage < threshold)
{
// If we currently have good battery, then make a note of when
// we went bad!
if ( lowbatt == false )
{
Timer = millis(); //set timer
}
lcd.setCursor(1, 0);
// Print a message to the LCD.
lcd.print("Battery Volts");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(6, 1);
// print voltage on A0:
lcd.print(voltage);
digitalWrite(ledPin, LOW);
lowbatt = true;
}
else
{
// This will clear the display if the voltage is great. So that's okay.
digitalWrite(ledPin, HIGH);
lcd.clear();
lowbatt = false;
}
// Now, let us clean the display if we are over the timer condition.
if ( lowbatt == true )
{
// So we know that the battery is flagged as low.
// Check the timer to see if we want to clear the screen
if (millis()-Timer >= 4000UL)
{
// Just clear the display!
lcd.clear();
}
}
}