I have a temp sensor and an LCD screen. I want the LCD screen to display the readings from the temp sensor (which it does)but when the readings from the temp sensor equal a thousand then I want the LCD screen to display in this case a bar graph until the readings from the temp sensor are less than 700. Then I want the LCD screen to go back to displaying the readings from the temp sensor. I think the answer is relatively simple but I'm not sure how to word this so Arduino would understand. If you're curious here is my code so far:
#include <LiquidCrystal.h>
#define lenght 16.0
double percent=100.0;
unsigned char b;
unsigned int peace;
LiquidCrystal lcd(4,5,6,7,8,9);
byte p1[10] = {
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10};
byte p2[10] = {
0x18,
0x18,
0x18,
0x18,
0x18,
0x18,
0x18,
0x18};
byte p3[10] = {
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C};
byte p4[10] = {
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E};
byte p5[10] = {
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F};
void setup() {
delay(100);
lcd.createChar(0, p1);
lcd.createChar(1, p2);
lcd.createChar(2, p3);
lcd.createChar(3, p4);
lcd.createChar(4, p5);
lcd.begin(16, 2);
}
void loop()
{
lcd.setCursor(0, 0);
unsigned int value = analogRead(0);
if(value++){
lcd.write("Temp");
lcd.write('=');
lcd.print(value-609);
}
if(value==1000){
lcd.clear();
while(value--){
if(value<700){
lcd.clear();
break;
}
percent = (value-700.0)/(1000.0-700.0)*100.0;
lcd.print(value);
lcd.print(" - ");
lcd.print(percent);
lcd.print(" % ");
lcd.setCursor(0,1);
double a=lenght/100*percent;
if (a>=1) {
for (int i=1;i<a;i++) {
lcd.print((char)4);
b=i;
}
a=a-b;
}
peace=a*5;
switch (peace) {
case 0:
break;
case 1:
lcd.print((char)0);
break;
case 2:
lcd.print((char)1);
break;
case 3:
lcd.print((char)2);
break;
case 4:
lcd.print((char)3);
break;
}
lcd.clear();
}
}
}
I think I'm pretty close to getting it to do what I wanted to do. But right now it does one of two things 1. because I have the LCD.Clear at the end when the temperature reaches 1000 it displays the way I want it to or so it seems but the LCD screen clears so much I can barely see it. When I put in a delay after the LCD.Clear command then the LCD doesn't display anything at all. Or 2.if I take out the LCD.Clear command then the LCD screen when the temperature reaches a thousand would display the bar graph but on the first row it would say for example 999 - 99.9% or 1000 - 100. 0% those numbers would remain the same until the temperature would reach less than 700 so the top row wouldn't display the current readings while the bottom row would display the bar graph but it the bar graph would go from a hundred percent down to 0% while the bar graph is going from 100% down to 0% the bottom row starts to display the correct information that the top row should be displaying. So really its all messed up without that LCD.Clear command. Any help is much appreciated.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.