From de590a555612ba18008cd9ac528d24e612c8b0eb Mon Sep 17 00:00:00 2001 From: sieja Date: Sun, 17 Aug 2025 18:39:01 +0200 Subject: [PATCH] =?UTF-8?q?Zwielokrotnienie=20p=C4=99tli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ESP32/LampkiBalkon/LampkiBalkon.ino | 97 +++++++++++++++++------------ 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/ESP32/LampkiBalkon/LampkiBalkon.ino b/ESP32/LampkiBalkon/LampkiBalkon.ino index 5f09b5c..76765f6 100644 --- a/ESP32/LampkiBalkon/LampkiBalkon.ino +++ b/ESP32/LampkiBalkon/LampkiBalkon.ino @@ -2,7 +2,7 @@ #include #include #include -#define Version "0.1.0" +#define Version "0.1.2" #define PinLED 2 // on-board LED #define IN1 32 @@ -32,70 +32,83 @@ void setup() { display.println("Version:"); display.setCursor(60, 0); display.println(Version); - display.display(); + display.display(); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(PinLED, OUTPUT); } + + void pulsujNaprzemiennie(int czasSekundy) { - const int steps = 400; // większa liczba = gładsze przejścia + const int steps = 600; // większa liczba = gładsze przejścia const int totalMillis = czasSekundy * 1000; const int delayPerStep = totalMillis / steps; + // display.clearDisplay(); + // display.setCursor(0, 20); + // display.println("1"); + // display.display(); + for (int i = 0; i < 20; i++) { - for (int i = 0; i <= steps; i++) { - float phase = (float)i / steps; - float angle = phase * PI; // pół cyklu (od 0 do π) - - // sinusoidalne przejście - float brightness1 = (cos(angle) + 1.0) / 2.0; // 1 → 0 - float brightness2 = 1.0 - brightness1; // 0 → 1 + for (int i = 0; i <= steps; i++) { + float phase = (float)i / steps; + float angle = phase * PI; // pół cyklu (od 0 do π) + + // sinusoidalne przejście + 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); + // 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); - delayMicroseconds(pulse1); - digitalWrite(IN1, LOW); + // Wysterowanie IN1 + digitalWrite(IN1, HIGH); + delayMicroseconds(pulse1); + digitalWrite(IN1, LOW); - // Wysterowanie IN2 - digitalWrite(IN2, HIGH); - delayMicroseconds(pulse2); - digitalWrite(IN2, LOW); + // Wysterowanie IN2 + digitalWrite(IN2, HIGH); + delayMicroseconds(pulse2); + digitalWrite(IN2, LOW); - // Opóźnienie (reszta czasu kroku) - delayMicroseconds(1000 * delayPerStep - pulse1 - pulse2); - } + // Opóźnienie (reszta czasu kroku) + delayMicroseconds(1000 * delayPerStep - pulse1 - pulse2); + } - // drugi półcykl: kolory zamienione miejscami (pełny cykl = 2x π) - for (int i = 0; i <= steps; i++) { - float phase = (float)i / steps; - float angle = phase * PI; + // drugi półcykl: kolory zamienione miejscami (pełny cykl = 2x π) + // display.clearDisplay(); + // display.setCursor(0, 20); + // display.println("2"); + // display.display(); - float brightness1 = (cos(angle) + 1.0) / 2.0; - float brightness2 = 1.0 - brightness1; + for (int i = 0; i <= steps; i++) { + float phase = (float)i / steps; + float angle = phase * PI; - int pulse1 = (int)(brightness2 * 2000); - int pulse2 = (int)(brightness1 * 2000); + float brightness1 = (cos(angle) + 1.0) / 2.0; + float brightness2 = 1.0 - brightness1; - digitalWrite(IN1, HIGH); - delayMicroseconds(pulse1); - digitalWrite(IN1, LOW); + int pulse1 = (int)(brightness2 * 2000); + int pulse2 = (int)(brightness1 * 2000); - digitalWrite(IN2, HIGH); - delayMicroseconds(pulse2); - digitalWrite(IN2, LOW); + digitalWrite(IN1, HIGH); + delayMicroseconds(pulse1); + digitalWrite(IN1, LOW); - delayMicroseconds(1000 * delayPerStep - pulse1 - pulse2); + digitalWrite(IN2, HIGH); + delayMicroseconds(pulse2); + digitalWrite(IN2, LOW); + + delayMicroseconds(1000 * delayPerStep - pulse1 - pulse2); + } } } void loop() { uint16_t lux = lightMeter.readLightLevel(); - if (lux < 10) { + if (lux < 10 || lux == -2) { digitalWrite(PinLED, LOW); pulsujNaprzemiennie(8); // pełny cykl 8 sekund } else { @@ -104,5 +117,7 @@ void loop() { display.println("OFF"); delay(5000); } - display.display(); + + + display.display(); }