+ wyświetlacz
This commit is contained in:
@@ -1,10 +1,20 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <BH1750.h>
|
#include <BH1750.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#define Version "0.1.0"
|
||||||
|
|
||||||
#define PinLED 2 // on-board LED
|
#define PinLED 2 // on-board LED
|
||||||
#define IN1 32
|
#define IN1 32
|
||||||
#define IN2 14
|
#define IN2 14
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 32
|
||||||
|
#define OLED_RESET -1
|
||||||
|
#define SCREEN_ADDRESS 0x3C
|
||||||
|
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
BH1750 lightMeter;
|
BH1750 lightMeter;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -12,6 +22,20 @@ void setup() {
|
|||||||
Wire.begin();
|
Wire.begin();
|
||||||
lightMeter.begin();
|
lightMeter.begin();
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
|
||||||
pinMode(IN1, OUTPUT);
|
pinMode(IN1, OUTPUT);
|
||||||
pinMode(IN2, OUTPUT);
|
pinMode(IN2, OUTPUT);
|
||||||
pinMode(PinLED, OUTPUT);
|
pinMode(PinLED, OUTPUT);
|
||||||
@@ -65,16 +89,34 @@ void pulsujNaprzemiennie(int czasSekundy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
display.clearDisplay();
|
||||||
|
|
||||||
uint16_t lux = lightMeter.readLightLevel();
|
uint16_t lux = lightMeter.readLightLevel();
|
||||||
Serial.print("Light: ");
|
Serial.print("Light: ");
|
||||||
Serial.print(lux);
|
Serial.print(lux);
|
||||||
Serial.println(" lx");
|
Serial.println(" lx");
|
||||||
|
|
||||||
if (lux < 10) {
|
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Luxy:");
|
||||||
|
display.setCursor(40, 0);
|
||||||
|
display.println(lux);
|
||||||
|
|
||||||
|
if (lux < 10 && lux >= 1) {
|
||||||
digitalWrite(PinLED, LOW);
|
digitalWrite(PinLED, LOW);
|
||||||
pulsujNaprzemiennie(5); // cykl trwa teraz 5 sekund
|
pulsujNaprzemiennie(5); // cykl trwa teraz 5 sekund
|
||||||
|
display.setCursor(0, 10);
|
||||||
|
display.println("Pulsowanie");
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(PinLED, HIGH);
|
digitalWrite(PinLED, HIGH);
|
||||||
delay(5 000);
|
display.setCursor(0, 10);
|
||||||
|
display.println("OFF");
|
||||||
|
if (lux < 1) {
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println("Zbyt ciemno");
|
||||||
|
}
|
||||||
|
delay(500);
|
||||||
}
|
}
|
||||||
|
display.display();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user