228 lines
7.0 KiB
C++
228 lines
7.0 KiB
C++
#include <SPI.h>
|
|
#include <Wire.h>
|
|
#include <Adafruit_GFX.h>
|
|
#include <Adafruit_SSD1306.h>
|
|
#include "DHT.h"
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
#define Version "0.1.0"
|
|
|
|
|
|
|
|
|
|
//2DO:
|
|
|
|
|
|
#define NUMPIXELS 10 //docelowo 9-10
|
|
|
|
#define DHTTYPE DHT22
|
|
|
|
#define SCREEN_WIDTH 128
|
|
#define SCREEN_HEIGHT 32
|
|
|
|
#define OLED_RESET -1
|
|
#define SCREEN_ADDRESS 0x3C
|
|
|
|
//PINS
|
|
#define BTN_DIMM 34 //GPIO34 D34
|
|
#define BTN_RST 35 //GPIO35 D35
|
|
#define BTN_HYGRSTT 36 //GPIO36 VP
|
|
#define BTN_SPEED 39 //GPIO35 VN
|
|
|
|
#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
|
|
|
|
|
|
|
|
//NEO PIXEL ARDESES:
|
|
#define NEOPXL_MULTIPLIER 25
|
|
// ARDESES:
|
|
#define ADR_NEOPXL_SPEED_1 0
|
|
#define ADR_NEOPXL_SPEED_2 1
|
|
#define ADR_NEOPXL_FILTER 2
|
|
#define ADR_NEOPXL_L1 3
|
|
#define ADR_NEOPXL_L2 4
|
|
#define ADR_NEOPXL_L3 5
|
|
#define ADR_NEOPXL_L4 6
|
|
#define ADR_NEOPXL_L5 7
|
|
#define ADR_NEOPXL_WATERLVL 8
|
|
#define ADR_NEOPXL_TANK 9
|
|
|
|
|
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
|
Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
|
DHT dht(DHTPIN, DHTTYPE);
|
|
|
|
|
|
|
|
//MAIN VALUES VARIABLES
|
|
int8_t resetVal = 0;
|
|
int8_t fanSpeedVal = 0;
|
|
int8_t hygrostatVal = 55;
|
|
int8_t dimmVal = 10;
|
|
|
|
float temp = 0.0;
|
|
float hum = 0.0;
|
|
|
|
|
|
//NEOPIXELS VARIABLES
|
|
int8_t neoPixelSwitch = 1;
|
|
int8_t neoPixelRed = 5;
|
|
int8_t neoPixelGreen = 5;
|
|
int8_t neoPixelBlue = 5;
|
|
|
|
int8_t neoPixelSpeed_1 = 1;
|
|
int8_t neoPixelSpeed_2 = 1;
|
|
int8_t neoPixelFilter = 1;
|
|
int8_t neoPixelLvl_1 = 1;
|
|
int8_t neoPixelLvl_2 = 1;
|
|
int8_t neoPixelLvl_3 = 1;
|
|
int8_t neoPixelLvl_4 = 1;
|
|
int8_t neoPixelLvl_5 = 1;
|
|
int8_t neoPixelWaterLvl = 1;
|
|
int8_t neoPixelTank = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IRAM_ATTR dimmButtonFcn() {
|
|
dimmVal ++;
|
|
if (dimmVal >= 11) {
|
|
dimmVal = 1;
|
|
}
|
|
}
|
|
void IRAM_ATTR speedButtonFcn() {
|
|
fanSpeedVal ++;
|
|
if (fanSpeedVal >= 3) {
|
|
fanSpeedVal = 0;
|
|
}
|
|
}
|
|
void IRAM_ATTR hygrostatButtonFcn() {
|
|
hygrostatVal = hygrostatVal + 10;
|
|
if (hygrostatVal >= 75) {
|
|
hygrostatVal = 35;
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
attachInterrupt(digitalPinToInterrupt(BTN_DIMM), dimmButtonFcn, FALLING);
|
|
attachInterrupt(digitalPinToInterrupt(BTN_SPEED), speedButtonFcn, FALLING);
|
|
attachInterrupt(digitalPinToInterrupt(BTN_HYGRSTT), hygrostatButtonFcn, FALLING);
|
|
dht.begin();
|
|
pixels.begin();
|
|
|
|
}
|
|
|
|
void loop() {
|
|
display.clearDisplay();
|
|
display.setCursor(90, 0);
|
|
display.println(Version);
|
|
|
|
|
|
display.setCursor(0, 0);
|
|
display.println("RST:");
|
|
display.setCursor(30, 0);
|
|
display.println(resetVal);
|
|
|
|
|
|
|
|
display.setCursor(0, 10);
|
|
display.println("FanSpd:");
|
|
display.setCursor(50, 10);
|
|
display.println(fanSpeedVal);
|
|
|
|
display.setCursor(70, 10);
|
|
display.println("Hygst:");
|
|
display.setCursor(115, 10);
|
|
display.println(hygrostatVal);
|
|
|
|
hum = (dht.readHumidity());
|
|
display.setCursor(0, 20);
|
|
display.println("Hum:");
|
|
display.setCursor(28, 20);
|
|
display.println(hum);
|
|
|
|
display.setCursor(70, 20);
|
|
display.println("Dimm:");
|
|
display.setCursor(115, 20);
|
|
display.println(dimmVal);
|
|
|
|
delay(50);
|
|
display.display();
|
|
|
|
// #################################################################
|
|
// #################################################################
|
|
//NEOPIXELS
|
|
// #################################################################
|
|
// #################################################################
|
|
// pixels.clear();
|
|
|
|
pixels.setPixelColor(ADR_NEOPXL_SPEED_1, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelSpeed_1, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelSpeed_1, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelSpeed_1));
|
|
pixels.setPixelColor(ADR_NEOPXL_SPEED_2, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelSpeed_2, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelSpeed_2, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelSpeed_2));
|
|
pixels.setPixelColor(ADR_NEOPXL_FILTER, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelFilter, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelFilter, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelFilter));
|
|
pixels.setPixelColor(ADR_NEOPXL_L1, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelLvl_1, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelLvl_1, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelLvl_1));
|
|
pixels.setPixelColor(ADR_NEOPXL_L2, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelLvl_2, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelLvl_2, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelLvl_2));
|
|
pixels.setPixelColor(ADR_NEOPXL_L3, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelLvl_3, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelLvl_3, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelLvl_3));
|
|
pixels.setPixelColor(ADR_NEOPXL_L4, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelLvl_4, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelLvl_4, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelLvl_4));
|
|
pixels.setPixelColor(ADR_NEOPXL_L5, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelLvl_5, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelLvl_5, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelLvl_5));
|
|
pixels.setPixelColor(ADR_NEOPXL_WATERLVL, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelWaterLvl, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelWaterLvl, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelWaterLvl));
|
|
pixels.setPixelColor(ADR_NEOPXL_TANK, pixels.Color(neoPixelRed*dimmVal*neoPixelSwitch*neoPixelTank, neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelTank, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelTank));
|
|
|
|
// pixels.show();
|
|
|
|
|
|
if (digitalRead(BTN_RST) == HIGH) {
|
|
unsigned long startTime = millis();
|
|
while (digitalRead(BTN_RST) == HIGH && millis() - startTime < 4000) {
|
|
display.clearDisplay();
|
|
display.setCursor(20, 0);
|
|
display.println("Resetowanie... 4s");
|
|
display.display();
|
|
delay(100);
|
|
}
|
|
if (digitalRead(BTN_RST) == HIGH) {
|
|
resetVal = 1;
|
|
display.clearDisplay();
|
|
display.setCursor(0, 0);
|
|
display.println("Zresetowano");
|
|
display.display();
|
|
delay(500);
|
|
}
|
|
}
|
|
|
|
delay(50);
|
|
// digitalWrite(PIN_SPEED_1, LOW);
|
|
// digitalWrite(PIN_SPEED_2, LOW);
|
|
}
|