Wersja uzyta, błedna
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
#define SCREEN_ADDRESS 0x3C
|
#define SCREEN_ADDRESS 0x3C
|
||||||
|
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
BH1750 lightMeter;
|
BH1750 lightMeter;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -22,7 +21,7 @@ void setup() {
|
|||||||
Wire.begin();
|
Wire.begin();
|
||||||
lightMeter.begin();
|
lightMeter.begin();
|
||||||
|
|
||||||
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
Serial.println(F("SSD1306 allocation failed"));
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,88 +34,75 @@ void setup() {
|
|||||||
display.println(Version);
|
display.println(Version);
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
|
|
||||||
pinMode(IN1, OUTPUT);
|
pinMode(IN1, OUTPUT);
|
||||||
pinMode(IN2, OUTPUT);
|
pinMode(IN2, OUTPUT);
|
||||||
pinMode(PinLED, OUTPUT);
|
pinMode(PinLED, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pulsujNaprzemiennie(int czasSekundy) {
|
void pulsujNaprzemiennie(int czasSekundy) {
|
||||||
const int steps = 150;
|
const int steps = 400; // większa liczba = gładsze przejścia
|
||||||
int delayPerStep = (czasSekundy * 1000) / (2 * steps); // ms
|
const int totalMillis = czasSekundy * 1000;
|
||||||
|
const int delayPerStep = totalMillis / steps;
|
||||||
|
|
||||||
for (int i = 0; i <= steps; i++) {
|
for (int i = 0; i <= steps; i++) {
|
||||||
float phase = (float)i / steps;
|
float phase = (float)i / steps;
|
||||||
float brightness1 = 1.0 - phase;
|
float angle = phase * PI; // pół cyklu (od 0 do π)
|
||||||
float brightness2 = phase;
|
|
||||||
|
|
||||||
int t_on1 = (int)(brightness1 * 2000);
|
// sinusoidalne przejście
|
||||||
int t_on2 = (int)(brightness2 * 2000);
|
float brightness1 = (cos(angle) + 1.0) / 2.0; // 1 → 0
|
||||||
|
float brightness2 = 1.0 - brightness1; // 0 → 1
|
||||||
|
|
||||||
|
// Konwersja jasności do długości impulsu (maks. 2000us)
|
||||||
|
int pulse1 = (int)(brightness1 * 2000);
|
||||||
|
int pulse2 = (int)(brightness2 * 2000);
|
||||||
|
|
||||||
|
// Wysterowanie IN1
|
||||||
digitalWrite(IN1, HIGH);
|
digitalWrite(IN1, HIGH);
|
||||||
digitalWrite(IN2, LOW);
|
delayMicroseconds(pulse1);
|
||||||
delayMicroseconds(t_on1);
|
|
||||||
|
|
||||||
digitalWrite(IN1, LOW);
|
digitalWrite(IN1, LOW);
|
||||||
|
|
||||||
|
// Wysterowanie IN2
|
||||||
digitalWrite(IN2, HIGH);
|
digitalWrite(IN2, HIGH);
|
||||||
delayMicroseconds(t_on2);
|
delayMicroseconds(pulse2);
|
||||||
|
|
||||||
digitalWrite(IN1, LOW);
|
|
||||||
digitalWrite(IN2, LOW);
|
digitalWrite(IN2, LOW);
|
||||||
delay(delayPerStep - 4);
|
|
||||||
|
// Opóźnienie (reszta czasu kroku)
|
||||||
|
delayMicroseconds(1000 * delayPerStep - pulse1 - pulse2);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = steps; i >= 0; i--) {
|
// drugi półcykl: kolory zamienione miejscami (pełny cykl = 2x π)
|
||||||
|
for (int i = 0; i <= steps; i++) {
|
||||||
float phase = (float)i / steps;
|
float phase = (float)i / steps;
|
||||||
float brightness1 = 1.0 - phase;
|
float angle = phase * PI;
|
||||||
float brightness2 = phase;
|
|
||||||
|
|
||||||
int t_on1 = (int)(brightness1 * 2000);
|
float brightness1 = (cos(angle) + 1.0) / 2.0;
|
||||||
int t_on2 = (int)(brightness2 * 2000);
|
float brightness2 = 1.0 - brightness1;
|
||||||
|
|
||||||
|
int pulse1 = (int)(brightness2 * 2000);
|
||||||
|
int pulse2 = (int)(brightness1 * 2000);
|
||||||
|
|
||||||
digitalWrite(IN1, HIGH);
|
digitalWrite(IN1, HIGH);
|
||||||
digitalWrite(IN2, LOW);
|
delayMicroseconds(pulse1);
|
||||||
delayMicroseconds(t_on1);
|
|
||||||
|
|
||||||
digitalWrite(IN1, LOW);
|
digitalWrite(IN1, LOW);
|
||||||
|
|
||||||
digitalWrite(IN2, HIGH);
|
digitalWrite(IN2, HIGH);
|
||||||
delayMicroseconds(t_on2);
|
delayMicroseconds(pulse2);
|
||||||
|
|
||||||
digitalWrite(IN1, LOW);
|
|
||||||
digitalWrite(IN2, LOW);
|
digitalWrite(IN2, LOW);
|
||||||
delay(delayPerStep - 4);
|
|
||||||
|
delayMicroseconds(1000 * delayPerStep - pulse1 - pulse2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
display.clearDisplay();
|
|
||||||
|
|
||||||
uint16_t lux = lightMeter.readLightLevel();
|
uint16_t lux = lightMeter.readLightLevel();
|
||||||
Serial.print("Light: ");
|
if (lux < 10) {
|
||||||
Serial.print(lux);
|
|
||||||
Serial.println(" lx");
|
|
||||||
|
|
||||||
|
|
||||||
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(8); // pełny cykl 8 sekund
|
||||||
display.setCursor(0, 10);
|
} else {
|
||||||
display.println("Pulsowanie");
|
|
||||||
} else {
|
|
||||||
digitalWrite(PinLED, HIGH);
|
digitalWrite(PinLED, HIGH);
|
||||||
display.setCursor(0, 10);
|
display.setCursor(0, 10);
|
||||||
display.println("OFF");
|
display.println("OFF");
|
||||||
if (lux < 1) {
|
delay(5000);
|
||||||
display.setCursor(0, 20);
|
|
||||||
display.println("Zbyt ciemno");
|
|
||||||
}
|
|
||||||
delay(500);
|
|
||||||
}
|
}
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user