Hello everyone,
I'd like to make clock with weather. I need to show the clock on the first line and on the second line scroll the: temperature, humidity and pressure.
- constantly display time on the first line
- Scroll the temperature to the beginning of the line
- Stop scrolling
- rewrite the temperature several times
- scroll the temperature away and scroll the humidity in
- Rewrite moisture several times
- Scroll the moisture away and scroll the pressure in
- Rewrite the pressure several times
But I need all of this without delay() or anything that suspends the code so that I can constantly check the status of the buttons.
all the other code is done, I just need to scroll the weather. here's my older code to show weather on both lines:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "DHT.h"
#define DHTPIN_22 8
#define DHTTYPE_22 DHT22
Adafruit_BMP085 bmp180;
float hum_22;
float temp_22;
float vyska;
float v;
String tlak;
String hum;
String temp;
int korekce = 32;
int x;
int z;
unsigned long previousMillis = 0;
unsigned long tlakMillis = 0;
const long interval = 5000;
DHT dht_22(DHTPIN_22, DHTTYPE_22);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
byte stupen[] = {
B00111,
B00101,
B00111,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup() {
dht_22.begin();
bmp180.begin();
lcd.begin(16, 2);
lcd.createChar(0, stupen);
delay(1000);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
///////////////////////////////////////
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
///////////////////////////////////////
//vyska = bmp180.readAltitude();
}
void loop() {
/////////////////////////////////////////////////////////////////////
analogWrite(9, map(analogRead(A0), 0, 1023, 255, 0));
analogWrite(10, map(analogRead(A0), 0, 1023, 254, 0));
analogWrite(11, map(analogRead(A0), 0, 1023, 255, 0));
/////////////////////////////////////////////////////////////////////
unsigned long currentMillis = millis();
if (currentMillis - tlakMillis >= 1000) {
tlakMillis = currentMillis;
tlak = (bmp180.readPressure() + korekce * 100) / 100.00;
v = bmp180.readAltitude() - vyska;
}
hum_22 = dht_22.readHumidity();
temp_22 = dht_22.readTemperature();
hum = dht_22.readHumidity();
temp = dht_22.readTemperature() - 0.7;
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
lcd.clear();
if (z == 0) {
z = 1;
}
else {
z = 0;
}
}
if (isnan(hum_22) || isnan(temp_22)) {
if (x == 0) {
lcd.clear();
}
if (z == 0) {
lcd.setCursor(0, 0);
lcd.print("Teplota: ");
lcd.print(temp_22);
lcd.setCursor(0, 1);
lcd.print("Vlhkost: ");
lcd.print(hum_22);
x = 1;
}
}
else {
if (z == 0) {
lcd.setCursor(0, 0);
lcd.print("Teplota: ");
lcd.print(temp[0]);
lcd.print(temp[1]);
lcd.print(temp[2]);
if (temp_22 < 0 | temp_22 > 9.9) {
lcd.print(temp[3]);
}
if (temp_22 <= -10) {
//lcd.print(temp[3]);
lcd.print(temp[4]);
}
if (temp_22 > -10) {
lcd.print(" ");
}
lcd.write(byte(0));
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Vlhkost: ");
if (hum_22 > 99.5) {
lcd.print("100");
}
else {
lcd.print(hum[0]);
if (hum_22 > 10) {
lcd.print(hum[1]);
}
}
lcd.print(" %");
x = 0;
}
}
if (z == 1) {
lcd.setCursor(0, 0);
lcd.print("Tlak: ");
lcd.print(tlak[0]);
lcd.print(tlak[1]);
lcd.print(tlak[2]);
lcd.print(tlak[3]);
lcd.print(tlak[4]);
lcd.print(tlak[5]);
lcd.print(" hPa");
/*lcd.setCursor(0, 1);
lcd.print("Vyska: ");
lcd.print(v);
lcd.print(" m");*/
}
}
I have some things in Czech so now you know what is that.