Go Down

Topic: Temperature and clock on 16 x 2 LCD, clearing issues (Read 699 times) previous topic - next topic

Apr 26, 2011, 09:45 pm Last Edit: Apr 26, 2011, 09:48 pm by faytoceanz3 Reason: 1
I need the 2nd row to clear every time for the clock, not the 1st row.

Top row I have the temperature reading
Bottom row I have the clock reading.
When I add "lcd.clear();" on the void digitalClockDisplay() section at the bottom, it clears the top row instead, which I don't want.  

How do I fix this issue?

Code: [Select]
#include <LiquidCrystal440.h>

#include <OneWire.h>
#include <DallasTemperature.h>
#include <DateTime.h>
#include <DateTimeStrings.h>

#define dt_SHORT_DAY_STRINGS
#define dt_SHORT_MONTH_STRINGS

#define ONE_WIRE_BUS 9

OneWire oneWire(ONE_WIRE_BUS);
int heater;
DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer = { 0x10, 0x37, 0xBC, 0x1E, 0x02, 0x08, 0x00, 0xE9 };

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int LED1 = 10; // heater pin location
int LED2 = 31; // heater LED indicator

void setup()
{ DateTime.sync(DateTime.makeTime(50, 59, 23, 16, 10, 2010));
 lcd.begin(16,2);
 pinMode(LED1, OUTPUT);  // heater pin location
 pinMode(LED2, OUTPUT);  // heater LED indicator
 // Start up the library
 sensors.begin();
 // set the resolution to 10 bit (good enough?)
 sensors.setResolution(insideThermometer, 10);
}



void loop()
{
 if(DateTime.available()) {
unsigned long prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;

DateTime.available(); //refresh the Date and time properties

digitalClockDisplay( ); // update digital clock
}
 sensors.requestTemperatures();
 printTemperature(insideThermometer);
 
 if (heater ==1){
   digitalWrite(LED1, HIGH); // Heater pin
   digitalWrite(LED2, HIGH); // Heater LED indicator
 } else {
   digitalWrite(LED1, LOW);  
   digitalWrite(LED2, LOW);
 
 }

}
void printTemperature(DeviceAddress deviceAddress)
{
 float tempC = sensors.getTempC(deviceAddress);
 
 lcd.setCursor(0,0);
 lcd.print("  Temp:");
 lcd.print(DallasTemperature::toFahrenheit(tempC));  
 lcd.print((char)223);
 lcd.print((char)70);
 

   
 if (DallasTemperature::toFahrenheit(tempC) < 75.00)
 heater = 1;
 else
 heater = 0;
}

void printDigits(byte digits){

// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits,DEC);
}

void digitalClockDisplay(){

//lcd.print(" ");
if(DateTime.Hour <10)
lcd.setCursor(5,1);
lcd.setCursor(4,1);


// digital clock display of current time

lcd.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
}



Si

Instead of using clear, just write spaces on top of the part you want to clear.
--
My New Arduino Book: http://www.arduinobook.com

I need to use lcd.clear(); for the clock portion because if i don't , the clock does not roll over correctly. 

Initially i have it set at 23:59:50, and after ten 10 seconds, it resets to 0:00:001 and counts up, which  changes the layout of the clock.


davekw7x

#3
Apr 27, 2011, 12:00 am Last Edit: Apr 27, 2011, 12:09 am by davekw7x Reason: 1

I need to use lcd.clear();...

Well, you really don't.  Not if you want to erase the characters on one row without affecting the other row.




    For an lcd module with two rows of 16 characters each:

    •  To erase all of the characters on row 0: Set the cursor to the beginning of row 0 and write 16 space characters.


    •  To erase all of the characters on row 1: Set the cursor to the beginning of row 1 and write 16 space characters.




    Regards,

    Dave

Footnote:
In addition to (or, maybe, instead of) selectively erasing the rows, I suggest that the display will look more professional if it doesn't jump around from one time to another.  In other words format the output so that for hour zero it looks like

00:00:00

or, maybe

<space>0:00:00

or whatever it takes to keep things in the same place from time to time.

Depending on how fast things work in your program, it might be more attractive just to rewrite the digits that change from one second/minute/hour to the next instead of erasing and rewriting the entire row.  (There may not even be a perceptible difference, but sometimes there is a "blinking" effect that can be annoying.)

Just a couple of suggestions based on personal opinion.

Sounds like a good idea, but

I'm kinda new to this so I'm not really sure how to do set it like 00:00:00.

Can you help me out?


davekw7x


...
I'm kinda new to this so I'm not really sure how to do set it like 00:00:00.
...


Here are routines that you can practice with.  I used Serial.print, but you can use lcd.print.

Numbers from 0-99 will occupy two digit positions in the output.

Code: [Select]

// If the value of the number is less than 10,
// print a space and the single digit.
//
// Otherwise print all digits of the decimal value.
//
printDigitsWithLeadingSpace(byte digits)
{
    if (digits < 10) {
        Serial.print(' '); // Or use lcd.print(' ');
    }
    Serial.print(digits,DEC); // Or use lcd.print(digits, DEC);
}
// If the value of the number is less than 10,
// print a zero and the single digit.
//
// Otherwise print all digits of the decimal value.
//
printDigitsWithLeadingZero(byte digits)
{
    if (digits < 10) {
        Serial.print('0'); // Or use lcd.print('0');
    }
    Serial.print(digits, DEC); // Or use lcd.print(digits, DEC);
}


So, call one of these instead of the following

Code: [Select]

lcd.print(DateTime.Hour,DEC);



Regards,

Dave

Great it works fine, but now I have a colon in the front of the time.

":23:59:50"

update portion of code:
Code: [Select]
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0

lcd.print(":");
if(digits < 10){
 
lcd.print('0');
}
lcd.print(digits,DEC);

}
void digitalClockDisplay(){

lcd.setCursor(0,0);

//lcd.print(" ");
if(DateTime.Hour<10)
lcd.setCursor(0,0);

// digital clock display of current time
printDigits(DateTime.Hour);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
}



davekw7x

#7
Apr 27, 2011, 04:55 pm Last Edit: Apr 27, 2011, 04:59 pm by davekw7x Reason: 1
...it works fine, but...


First, some notes:

  • The way it is written, the function in the sketch prints a colon before the digits value.

  • Therefore, if you don't want a colon for a particular value, don't use the function in the sketch the way that is written.

  • Neither of the functions that I posted prints a colon.  That is why I suggested you practice using them.  So that you could see what they do.



I can think of a couple of possibilities:

1.
Add one of the functions that I posted to the sketch and call this new function to print the hours.
Call the previously existing function to print colon and minutes
Call the previously existing function to print colon and seconds


2.
Modify the function in the sketch so that it doesn't print a colon.
Call the modified function to print the hours
Call  Serial.print(':');
Call the modified function to print the minutes.
Call  Serial.print(':');
Call the modified function to print the seconds.

Bottom line: I know that when you are new it's all pretty strange.  Using code from other people's sketches to accomplish a similar task is sometimes a good learning experience.

But...

The best experience is if you look at the code (yes, really look) to try to see what it is doing.  Get something to work or "almost work" the way that you want it to.  Then modify the code and see what happens.  If you have any questions it's always OK to ask.


Regards,

Dave

Go Up