Dodanie czujnika światła BH1750

OBsługa Red/White LED TANK
Próa z fotorezystorem
This commit is contained in:
sieja
2025-06-08 21:59:53 +02:00
parent 4175a31746
commit fea3421475

View File

@@ -4,8 +4,9 @@
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include "DHT.h" #include "DHT.h"
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#include <BH1750.h>
#define Version "0.1.0" #define Version "0.2.0"
@@ -41,6 +42,7 @@
#define NEOPIXEL 27 //GPIO04 D27 #define NEOPIXEL 27 //GPIO04 D27
#define IN_PHOTOTRA 12
//NEO PIXEL ARDESES: //NEO PIXEL ARDESES:
@@ -61,6 +63,7 @@
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXEL, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXEL, NEO_GRB + NEO_KHZ800);
DHT dht(DHTPIN, DHTTYPE); DHT dht(DHTPIN, DHTTYPE);
BH1750 lightMeter;
@@ -101,12 +104,15 @@ void IRAM_ATTR dimmButtonFcn() {
if (dimmVal >= 11) { if (dimmVal >= 11) {
dimmVal = 1; dimmVal = 1;
} }
digitalWrite(LED_WHT_TANK, HIGH);
} }
void IRAM_ATTR speedButtonFcn() { void IRAM_ATTR speedButtonFcn() {
fanSpeedVal ++; fanSpeedVal ++;
if (fanSpeedVal >= 3) { if (fanSpeedVal >= 3) {
fanSpeedVal = 0; fanSpeedVal = 0;
} }
digitalWrite(LED_RED_TANK, HIGH);
} }
void IRAM_ATTR hygrostatButtonFcn() { void IRAM_ATTR hygrostatButtonFcn() {
hygrostatVal = hygrostatVal + 10; hygrostatVal = hygrostatVal + 10;
@@ -138,15 +144,31 @@ void setup() {
pinMode(BTN_HYGRSTT, INPUT); pinMode(BTN_HYGRSTT, INPUT);
pinMode(PIN_SPEED_1, OUTPUT); pinMode(PIN_SPEED_1, OUTPUT);
pinMode(PIN_SPEED_2, OUTPUT); pinMode(PIN_SPEED_2, OUTPUT);
pinMode(LED_RED_TANK, OUTPUT);
pinMode(LED_WHT_TANK, OUTPUT);
pinMode(IN_PHOTOTRA, INPUT);
attachInterrupt(digitalPinToInterrupt(BTN_DIMM), dimmButtonFcn, FALLING); attachInterrupt(digitalPinToInterrupt(BTN_DIMM), dimmButtonFcn, FALLING);
attachInterrupt(digitalPinToInterrupt(BTN_SPEED), speedButtonFcn, FALLING); attachInterrupt(digitalPinToInterrupt(BTN_SPEED), speedButtonFcn, FALLING);
attachInterrupt(digitalPinToInterrupt(BTN_HYGRSTT), hygrostatButtonFcn, FALLING); attachInterrupt(digitalPinToInterrupt(BTN_HYGRSTT), hygrostatButtonFcn, FALLING);
Wire.begin();
lightMeter.begin();
dht.begin(); dht.begin();
pixels.begin(); pixels.begin();
} }
void loop() { void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
display.clearDisplay(); display.clearDisplay();
display.setCursor(90, 0); display.setCursor(90, 0);
display.println(Version); display.println(Version);
@@ -170,11 +192,17 @@ void loop() {
display.println(hygrostatVal); display.println(hygrostatVal);
hum = (dht.readHumidity()); hum = (dht.readHumidity());
display.setCursor(0, 20); // display.setCursor(0, 20);
display.println("Hum:"); // display.println("Hum:");
display.setCursor(28, 20); // display.setCursor(28, 20);
display.println(hum); // display.println(hum);
int photoVal = analogRead(IN_PHOTOTRA);
display.setCursor(0, 20);
display.println("Ph:");
display.setCursor(28, 20);
display.println(photoVal);
display.setCursor(70, 20); display.setCursor(70, 20);
display.println("Dimm:"); display.println("Dimm:");
display.setCursor(115, 20); display.setCursor(115, 20);
@@ -224,7 +252,10 @@ void loop() {
} }
} }
delay(50); delay(500);
digitalWrite(LED_WHT_TANK, LOW);
digitalWrite(LED_RED_TANK, LOW);
// digitalWrite(PIN_SPEED_1, LOW); // digitalWrite(PIN_SPEED_1, LOW);
// digitalWrite(PIN_SPEED_2, LOW); // digitalWrite(PIN_SPEED_2, LOW);
} }