Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <SPI.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BMP280.h>
- #include <AM2320.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <LiquidCrystal.h>
- //LiquidCrystall
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- //DS18B20
- #define ONE_WIRE_BUS 2
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- #define RIGHT 0
- #define UP 1
- #define DOWN 2
- #define LEFT 3
- #define SELECT 4
- #define NONE 5
- AM2320 th;
- Adafruit_BMP280 bme; // I2C
- int temp, hum, pres;
- int vent =24;
- int lcd_key = 0;
- int adc_key_in = 0;
- long previousMillis =0;
- int interval = 750;
- bool boolTemp=true, boolHum=true, boolPres=true;
- int read_LCD_buttons(){
- adc_key_in = analogRead(0);
- if (adc_key_in > 1000) return NONE;
- if (adc_key_in < 50) return RIGHT;
- if (adc_key_in < 150) return UP;
- if (adc_key_in < 300) return DOWN;
- if (adc_key_in < 450) return LEFT;
- if (adc_key_in < 700) return SELECT;
- return NONE;
- }
- void setup() {
- lcd.begin(16,2);
- pinMode(11, OUTPUT);
- Serial.begin(9600);
- Serial.println(F("BMP280 test"));
- if (!bme.begin(0x76)) {
- Serial.println("Could not find a valid BMP280 sensor, check wiring!");
- while (1);
- }
- }
- void loop() {
- unsigned long currentMillis = millis();
- //Knöpfe
- lcdkey();
- //DS18B20
- sensors.requestTemperatures();
- temp = sensors.getTempCByIndex(0);
- if(temp== -127){
- temp = th.t;
- }
- Serial.print("Temp: ");
- Serial.print(temp);
- Serial.print("*C");
- Serial.println();
- //AM2320B
- switch(th.Read()) {
- case 2:
- Serial.println("CRC failed");
- break;
- case 1:
- Serial.println("Sensor offline");
- break;
- case 0:
- hum = th.h;
- Serial.print("hum: ");
- Serial.print(hum);
- Serial.println();
- break;
- }
- //BMP280
- pres=bme.readPressure();
- Serial.print("Pres: ");
- Serial.print(pres);
- Serial.println(" Pa");
- //DisplayAusgabe
- lcd.setCursor(0,1);
- if(boolTemp==true){
- lcd.print("temp: ");
- lcd.print(temp);
- lcd.print("*C ");
- }
- if(boolHum==true){
- lcd.print("hum: ");
- lcd.print(hum);
- lcd.print("% ");
- }
- if(boolPres==true){
- lcd.print("pres: ");
- lcd.print(pres);
- lcd.print("Pa ");
- }
- lcd.setCursor(0,0);
- lcd.print("Vent ab: ");
- lcd.print(vent);
- lcd.print(" C");
- /*if(millis()%500==0){
- if(positionCounter<18){
- lcd.scrollDisplayLeft();
- positionCounter++;
- }else{
- positionCounter=0;
- }
- }*/
- int subMillis = currentMillis - previousMillis;
- Serial.println(subMillis);
- if(subMillis > interval){
- previousMillis = currentMillis;
- for (int positionCounter = 0; positionCounter < 1; positionCounter) {
- // scrolled eins nach links
- lcd.scrollDisplayLeft();
- positionCounter++;
- }
- }
- if(temp<vent){
- digitalWrite(11, LOW);
- }
- if(temp>=vent){
- digitalWrite(11, HIGH);
- }
- }
- void lcdkey(){
- lcd_key = read_LCD_buttons();
- switch(lcd_key){
- case UP:{
- vent++;
- break;
- }
- case DOWN:{
- vent--;
- break;
- }
- }
- lcd.setCursor(0,0);
- lcd.print("Vent ab: ");
- lcd.print(vent);
- lcd.print(" C");
- }
Advertisement
Add Comment
Please, Sign In to add comment