#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#include <Adafruit_NeoPixel.h>


#define Version "0.3"


#define NUMPIXELS 1  //docelowo 8-9

#define DHTTYPE DHT22

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

#define OLED_RESET     -1
#define SCREEN_ADDRESS 0x3C

#define BTN_RST       35    //GPIO35    D35
#define BTN_DIMM      34    //GPIO34    D34
#define BTN_SPEED     39    //GPIO35    VN
#define BTN_HYGRSTT   36    //GPIO36    VP

#define PIN_SPEED_1   32    //GPIO32    D32
#define PIN_SPEED_2   14    //GPIO36    D14

#define DHTPIN        4     //GPIO04    D4

#define LED_WHT_TANK  26    //GPIO26    D26
#define LED_RED_TANK  25    //GPIO25    D25

#define NEOPIXEL      27    //GPIO04    D27

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXEL, NEO_GRB + NEO_KHZ800);
DHT dht(DHTPIN, DHTTYPE);


float temp = 0.0;
float hum = 0.0;


void setup() {
  Serial.begin(9600);
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
  }

  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.clearDisplay();
  display.setCursor(0, 0);
  display.println("Version:");
  display.setCursor(60, 0);
  display.println(Version);
  display.display();

  delay(500);
  pinMode(BTN_RST, INPUT);
  pinMode(BTN_DIMM, INPUT);
  pinMode(BTN_SPEED, INPUT);
  pinMode(BTN_HYGRSTT, INPUT);
  pinMode(PIN_SPEED_1, OUTPUT);
  pinMode(PIN_SPEED_2, OUTPUT);
  dht.begin();
  pixels.begin();

}

void loop() {
    display.clearDisplay();
    display.setCursor(0, 0);
    display.println("Testy:");

    
    if (digitalRead(BTN_RST) == HIGH) {
        display.setCursor(0, 10);
        display.println("BTN_RST:");
    }

    if  (digitalRead(BTN_DIMM) == HIGH) {
        display.setCursor(0, 10);
        display.println("BTN_DIMM");
    }
    if  (digitalRead(BTN_SPEED) == HIGH) {
        display.setCursor(0, 10);
        
        display.println("BTN_SPEED");
        digitalWrite(PIN_SPEED_1, HIGH);

    }
    if  (digitalRead(BTN_HYGRSTT) == HIGH) {
        display.setCursor(0, 10);
        display.println("BTN_HYGRSTT");
        digitalWrite(PIN_SPEED_2, HIGH);

    }


    temp = (dht.readTemperature());
    display.setCursor(0, 20);
    display.println(temp);
    
    display.display();

//    #################################################################
//    #################################################################
//NEOPIXELS
//    #################################################################
//    #################################################################
    pixels.clear();

    pixels.setPixelColor(0, pixels.Color(10, 0, 0));
    pixels.show(); 
    delay(500); 
    pixels.setPixelColor(0, pixels.Color(0, 10, 0));
    pixels.show(); 
    delay(500); 
    pixels.setPixelColor(0, pixels.Color(0, 0, 10));
    pixels.show(); 
    delay(500); 
    pixels.setPixelColor(0, pixels.Color(10, 10, 0));
    pixels.show(); 
    delay(500); 
    pixels.setPixelColor(0, pixels.Color(0, 10, 10));
    pixels.show(); 
    delay(500); 
    pixels.setPixelColor(0, pixels.Color(10, 0, 10));
    pixels.show(); 
    delay(500); 
    pixels.setPixelColor(0, pixels.Color(10, 10, 10));
    pixels.show(); 
    delay(1300); 

    
    delay(300);  
    digitalWrite(PIN_SPEED_1, LOW);
    digitalWrite(PIN_SPEED_2, LOW);
 
}
