Mein Plan ist eine Adventhaus Beleuchtung (Modellbau) wo sich jeden Tag vom 1. Dezember bis zum 24. Dezember um 9 Uhr ein Fenster einschalten soll und um 17 Uhr alle bis zu den aktuellen Tag aktiven Fenster dazu einschalten und um 22 Uhr sich alle ausschalten und dann am nächsten Tag um 9 Uhr mit dem aktuellen Fenster wieder alles beginnt. Das alles ist echt Neuland für mich ich habe schon einiges verstanden oder versucht zu verstehen und versuche auch immer mit Beispielen zu arbeiten. Da ich am besten durch probieren lerne.
Der zusammengeflickte Sketch funktioniert teilweise ja schon. Habe aber jetzt ein Problem gefunden und versuche verzweifelt es zu lösen.
Ich habe einen WS2812 Strip und ein DS3231RTC und einen Arduino Uno R4 verbaut und die einzelnen Pixel in die Fenster eingebaut. Mein Problem ist mir erst jetzt aufgefallen: Wie kann ich an einen bestimmten Tag ein bestimmtes Pixel leuchten lassen. im Versuch hat es geklappt da hatte ich nur 24 Pixel am Strip. und da habe ich einfach den Tag "now.day()" auch gleich als Pixelnummer genommen. Jetzt sind mehrere verbaut. Im Sketch hab ich jetzt nur 5.
Zum testen hab ich immer die Variablen geändert.
Wie schaffe ich das, das ich z.B. am Tag 12 die Pixel 40 leuchten lasse.
Für mein zweites Problem das die bereits aktivierten Pixel, also am Tag 12 alle Pixel von 1-12 von 17 - 22 Uhr leuchten, bin ich für Hilfe und Tips dankbar. Werde da aber auch selber weitertüfteln.
Vielen Dank im voraus.
Der Sketch ist für euch sicher nur Salat. Sorry
/*
Versuch für eine Adventhaus Beleuchtung (Modellbau) wo sich jeden Tag vom 1. Dezember bis zum 24. Dezember um 9 Uhr
ein Fenster einschalten soll und um 17 Uhr alle bis zu den aktuellen Tag aktiven Fenster dazu einschalten
und um 22 Uhr sich alle ausschalten und dann am nächsten Tag um 9 Uhr mit dem aktuellen Fenster wieder alles
beginnt.
Im Oktober läuft das Halloween Programm und in der restlichen Zeit das Standart Programm.
Möchte später das ganze mit Musik zu jeden Fenster um 9 Uhr erweitern.
*/
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6 // DatenPIN für den LED Strip
#define PIXELCOUNT 126 // Anzahl der LEDs auf dem Strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELCOUNT, PIN, NEO_GRB + NEO_KHZ800);
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
Serial.begin(9600);
rtc.begin();
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
strip.begin();
strip.setBrightness(50); // Helligkeit (1-255)
strip.show(); // Schaltet alle LEDs am Anfang aus
delay(1000); // wartet 1 Sekunden
}
void loop() {
int StartH = 10; // Das Monat für Halloween
int StartA = 12; // Das Monat für den Adventkalender
int FensterTime = 9; // Startzeit für das aktuelle Fenster - alle anderen sind aus
int AlleFensterE = 17; // Alle bisherigen Fenster einschalten - 17 Uhr
int AlleFensterA = 22; // Alle Fenster ausschalten - 22 Uhr
DateTime now = rtc.now();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
if ((now.month()) == StartA && (now.hour()) == FensterTime) {
strip.setPixelColor(now.day(), 0, 0, 255);
Serial.println("Das aktuelle Fenster leuchtet von 9-10 Uhr");
} else if ((now.month()) == StartA && (now.day()) <= now.day() && (now.hour()) == AlleFensterE) {
strip.setPixelColor(1, 0, 0, 255);
strip.setPixelColor(2, 0, 0, 255);
strip.setPixelColor(3, 0, 0, 255);
strip.setPixelColor(4, 0, 0, 255);
strip.setPixelColor(5, 0, 0, 255);
Serial.println("Alle Fenster bis zum aktuellen Tag leuchten von 17-22 Uhr");
} else if ((now.month()) == StartH) {
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness
theaterChase(strip.Color(0, 0, 127), 50); // Blue, half brightness
rainbow(10); // Flowing rainbow cycle along the whole strip
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
Serial.println(now.day());
Serial.println("Halloween Programm");
} else {
Serial.println("Standart Programm");
Serial.println("Folgt noch.");
}
strip.show();
previousMillis = currentMillis;
}
}
void colorWipe(uint32_t color, int wait) {
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void theaterChase(uint32_t color, int wait) {
for (int a = 0; a < 10; a++) { // Repeat 10 times...
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
for (int c = b; c < strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}
void rainbow(int wait) {
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
strip.rainbow(firstPixelHue);
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
void theaterChaseRainbow(int wait) {
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for (int a = 0; a < 30; a++) { // Repeat 30 times...
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
for (int c = b; c < strip.numPixels(); c += 3) {
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
}
}
