countDecko

Untitled

Jun 1st, 2019
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////BIBLIOTEKI
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <Adafruit_Sensor.h>
  5. #include "Adafruit_BME680.h"
  6. #include <Wire.h>
  7. #include <LiquidCrystal_I2C.h>
  8.  
  9. ////////SENZOR
  10. #define BME_SCK 13
  11. #define BME_MISO 12
  12. #define BME_MOSI 11
  13. #define BME_CS 10
  14. #define SEALEVELPRESSURE_HPA (1013.25)
  15. Adafruit_BME680 bme; // I2C
  16. //Adafruit_BME680 bme(BME_CS); // hardware SPI
  17. //Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
  18.  
  19. ///////EKRAN
  20. #define BACKLIGHT_PIN 9
  21. LiquidCrystal_I2C lcd(0x38, BACKLIGHT_PIN, POSITIVE);  // Set the LCD I2C address
  22. const uint8_t charBitmap[][8] = {
  23.   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
  24.   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
  25.   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
  26.   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
  27.   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
  28.   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
  29.   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
  30.   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
  31.  
  32. };
  33.  
  34.  
  35. ////////MOTOR
  36. #define MOTOR_PIN 8
  37.  
  38. void setup() {
  39.   pinMode(MOTOR_PIN, OUTPUT);
  40.  
  41.  
  42.   Serial.begin(9600);
  43.   while (!Serial);
  44.   Serial.println(F("BME680 test"));
  45.   if (!bme.begin()) {
  46.     Serial.println("Could not find a valid BME680 sensor, check wiring!");
  47.     while (1);
  48.   }
  49.   // Set up oversampling and filter initialization
  50.   bme.setTemperatureOversampling(BME680_OS_8X);
  51.   bme.setHumidityOversampling(BME680_OS_2X);
  52.   bme.setPressureOversampling(BME680_OS_4X);
  53.   bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  54.   bme.setGasHeater(320, 150); // 320*C for 150 ms
  55.  
  56.  
  57.   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
  58.   // Switch on the backlight
  59.   pinMode ( BACKLIGHT_PIN, OUTPUT );
  60.   digitalWrite ( BACKLIGHT_PIN, HIGH );
  61.   lcd.begin(16, 2);              // initialize the lcd
  62.   for ( int i = 0; i < charBitmapSize; i++ )
  63.   {
  64.     lcd.createChar ( i, (uint8_t *)charBitmap[i] );
  65.   }
  66.   lcd.home ();
  67. }
  68.  
  69. void loop() {
  70.   if (! bme.performReading()) {
  71.     Serial.println("Failed to perform reading :(");
  72.     return;
  73.   }
  74.  
  75.   int temp = bme.temperature;
  76.  
  77.   if(temp > 30){
  78.     digitalWrite(MOTOR_PIN, HIGH);
  79.   }
  80.  
  81.   delay(2000);
  82.   lcd.setCursor(0,0);
  83.   lcd.print("temp: ");
  84.   lcd.print(temp);
  85.   lcd.setCursor(0,1);
  86.   lcd.print("FAN: ");
  87.   if(digitalRead(MOTOR_PIN) == LOW) lcd.print("ON");
  88.   else lcd.print("OFF");
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment