Habe hier mal den bisherigen sketch reingeschrieben.
Laufen tut er schon.
Es geht um den letzten Abschnitt.
Der läuft halt testweise nun, un macht die Zeile auch einmal voll, wurstelt sich aber dann natürlich durchs ganze Display.
Daran feile ich gerade, hoffentlich mit Hilfe von euch.
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Sodaq_BMP085.h>
/*
* Written by skyfox60, but also with some copy paste from the arduino examples
*
* LCD RS pin to digital pin 7
* LCD Enable pin to digital pin 2
* LCD D4 pin to digital pin 3
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 5
* LCD D7 pin to digital pin 6
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor 1:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3) thats for the contrast
* 10K resistor 2:
* ends to +5V and ground
* wiper to pin (pin A1) thats to set the brightness
* Backlight Anode brightness pin 11
* GND to Kathode
* D12 = DHT22 input
*/
#define brightnessPWM 10
#define DHTPIN 12
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
Sodaq_BMP085 bmp;
float Druck;
long D;
//Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
const int rs = 7, en = 2, d4 = 3, d5 = 4, d6 = 5, d7 = 6;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned long interval = 1000 ; // use will be named later
unsigned long interval2 = 2000 ; // Time after which the actual Temp is measured and refresht on display
unsigned long currentMillis = millis() ; // used to count the time to refresh the actual Temp on display
unsigned long previousMillis = 0 ; // for the interval of refreshing the actual temp
unsigned long currentgraphMillis = millis() ; // used to count the time to refresh the actual Temp on display
unsigned long previousgraphMillis = 0 ; // for the interval of refreshing the actual temp
float tempC = 0.00;
int Ledpin = 13; // not even necessary, used it during debug, but, set temp limit very near to actual temp and you´ll see it flash, but Relais is stable due to smoothing.
// if you switch you Relais with the same condition, it will go on/off/on/off several times before heater is stably switched on. thats why the 1000/60000 Interval is given.
int HUM;
int brightness;
int CP = 0; // cursorposition
int VP; // maps actual pressure to values of 1 to 8 for the grahic display characters
unsigned char valtable[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
int counter //
// make some custom characters: out of the examples, I just coy/paste it, not all needed here.
byte eight[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
byte seven[8] = {
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
byte six[8] = {
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
byte five[8] = {
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
byte four[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111
};
byte three[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111
};
byte two[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111
};
byte one[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111
};
void setup()
{
pinMode (Ledpin, OUTPUT);
pinMode (A1, INPUT);
analogWrite (brightnessPWM,255);
lcd.begin(20, 4);
Serial.begin(9600); //necessary only for debug
dht.begin();
bmp.begin();
lcd.createChar(0, one); // create a new character
lcd.createChar(1, two); // create a new character
lcd.createChar(2, three); // create a new character
lcd.createChar(3, four); // create a new character
lcd.createChar(4, five); // create a new character
lcd.createChar(5, six); // create a new character
lcd.createChar(6, seven); // create a new character
lcd.createChar(7, eight); // create a new character
delay(10);
lcd.clear();
lcd.setCursor(0,0);
int HUM = dht.readHumidity();
delay(3000);
//lcd.clear();
}
//finally getting started
void loop()
{
int B = analogRead (A1);
//Serial.println(B);
brightness=map(B,0,1024,3,255);
analogWrite (brightnessPWM,brightness);
// time to refresh the display an to do the real work ( switching the relais )
//Zeit, mal das Display zu aktualisieren und die eigentliche Arbeit zu erledigen, das Schalten des Relais
currentMillis = millis();
// Serial.println( currentMillis - previousMillis);
//Serial.println( currentsmoothMillis - previoussmoothMillis);
if (currentMillis - previousMillis >= interval2){
previousMillis = currentMillis ;
tempC = dht.readTemperature();
HUM = dht.readHumidity();
//Serial.print("Temperature = ");
// Serial.print("Pressure = ");
D = bmp.readPressure();
//Serial.println (D);
lcd.setCursor(0, 0);
lcd.print("T = ");
lcd.print(tempC,1);
lcd.write(0xDF),lcd.print("C "),lcd.print(millis());
lcd.setCursor(0,1);
//lcd.print("Rel. Luftfeuchte");
//lcd.setCursor(0,1);
//lcd.print(" betr\xE1"); lcd.print("gt ");
lcd.print("F = "),lcd.print(HUM);
lcd.print("%");
Druck = D/100.0;
lcd.setCursor(0,2);
lcd.print("D = ");
lcd.print(Druck,2);
lcd.print(" hPa");
//HIER GEHT MEINE FRAGE LOS; DAS HIER UNTERHALB MÖCHTE ICH OPTIMIEREN
currentgraphMillis = millis();
// Serial.println( currentMillis - previousMillis);
//Serial.println( currentsmoothMillis - previoussmoothMillis);
if (currentgraphMillis - previousgraphMillis >= interval){
previousgraphMillis = currentgraphMillis ;
VP = map(Druck,990,1040,0,7);
lcd.setCursor(CP,3);
lcd.write((byte)VP);
CP++;
Serial.println(CP);
Serial.println(VP);
}
lcd.setCursor(0,0);
} }