Hi,
I think I've made a mistake, but cant find it after watching the code over and over again, maybe you can help.
What I want:
I have a temperature sensor, a RTC module and a LCD Display (16x2) over 74hc595
I would like to have 2 screens on the LCD, changing every x seconds.
Screen 1:
TEXT
Temperature - Time
Screen 2:
Date
Temperature - Time
I cant get it switching to screen 2. And I want the temperature updated during displaying the screens. Thats why I tried to do it with a while loop.
Here is my while code inside of the loop:
var1 = 0;
while(var1 < 2) {
lcd1.setCursor(0, 0);
lcd1.print(" TEXT ");
// ------------------ Temp Sensor -----------------------
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
//Serial.println("No more addresses.");
//Serial.println();
ds.reset_search();
return;
}
//Serial.print("ROM =");
for( i = 0; i < 8; i++) {
//Serial.write(' ');
//Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
type_s = 1;
break;
case 0x28:
type_s = 0;
break;
case 0x22:
type_s = 0;
break;
default:
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
// ------------------------- Temp Sensor Ende ----------------------------
lcd1.setCursor(0, 1);
lcd1.print(celsius);
lcd1.print((char)223);
lcd1.print(' ');
printTime(local, tcr -> abbrev);
var1++;
}
// ------------------ LCD Ausgabe 1 -----------------------
// ------------------ LCD Ausgabe 2 -----------------------
var2 = 0;
while(var2 < 2) {
lcd1.setCursor(0, 0);
printDate(local, tcr -> abbrev);
// ------------------ Temp Sensor -----------------------
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
//Serial.println("No more addresses.");
//Serial.println();
ds.reset_search();
return;
}
//Serial.print("ROM =");
for( i = 0; i < 8; i++) {
//Serial.write(' ');
//Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
type_s = 1;
break;
case 0x28:
type_s = 0;
break;
case 0x22:
type_s = 0;
break;
default:
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
// ------------------------- Temp Sensor Ende ----------------------------
lcd1.setCursor(0, 1);
lcd1.print(celsius);
lcd1.print((char)223);
lcd1.print(' ');
printTime(local, tcr -> abbrev);
var2++;
}
// ------------------ LCD Ausgabe 2 -----------------------