Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76d6ee900c | ||
|
|
20fc9092e6 | ||
|
|
deb5f3e500 | ||
|
|
ca0e6afa8f | ||
|
|
f072bbf575 | ||
|
|
f70d007811 | ||
|
|
251d3a20fb | ||
|
|
1c79c9f5ef | ||
|
|
917d832b18 | ||
|
|
736ee4b4b1 | ||
|
|
d22249c5a4 | ||
|
|
d3af2efdc8 | ||
|
|
8d3e0001a4 | ||
|
|
183b316459 | ||
|
|
f8dd93edbc | ||
|
|
ce1f39b043 | ||
|
|
77124df55b | ||
|
|
5334c152eb | ||
|
|
fce7ac94f7 | ||
|
|
7a0abb0285 | ||
|
|
950016a457 | ||
|
|
434cc44607 | ||
|
|
2366dc790e | ||
|
|
f21094a404 | ||
|
|
2b6977a97e | ||
|
|
d7bdae65df | ||
|
|
bb8da924df | ||
|
|
cadd97909d | ||
|
|
5162083180 | ||
|
|
396138383e | ||
|
|
26ace4849c | ||
|
|
106a8be897 | ||
|
|
bebbc539cc | ||
|
|
50272d6ed5 | ||
|
|
3e770bdcac | ||
|
|
472ae25cb9 | ||
|
|
64e3a5eb05 | ||
|
|
043742dccf |
No files matched your search
@@ -0,0 +1,2 @@
|
||||
# SSH-Schluessel nie committen
|
||||
.ssh/
|
||||
@@ -1,16 +1,74 @@
|
||||
# Wordclock
|
||||
|
||||
Firmware für die WordClock vom c3e.
|
||||
> **⚠️ Hinweis:** Dieses Projekt ist aktuell nicht ausgereift. Die neue Version befindet sich noch im Aufbau, daher sind Teile dieser Anleitung (z. B. Dateipfade und Links) veraltet.
|
||||
|
||||
## Anleitung
|
||||
Firmware für die WordClock (in der Art von https://www.amazon.de/dp/B01N5TKXP3/) vom c3e. Als Rahmen bietet sich ["RIBBA" von IKEA](https://www.ikea.com/de/de/catalog/products/40378401/) an.
|
||||
Außerdem wird benötigt:
|
||||
* Ein ESP8266 (z.B. [WeMos D1 Mini](https://www.amazon.de/dp/B076F53B6S/))
|
||||
* Ein LED-Strip WS8212 mit 60 LED/m, 1m reicht (also 60 LED) z.B. von eBay
|
||||
* Kabel in 3 Farben, am besten Draht, Litze 3-adrig flach geht notfalls auch
|
||||
* Ein USB-Netzteil mit genügend Leistung z.B. https://www.amazon.de/dp/B00WLI5E3M
|
||||
* Ein USB-Kabel
|
||||
* Etwa 2.5 m² MDF (Mitteldichte Faserplatte) 2,5mm die gelasert wird
|
||||
* Karton zum Lasern der Worte
|
||||
* Viel Geduld beim Löten
|
||||
|
||||
## Hardware
|
||||
|
||||
Die MDF-Platte zuschneiden und mit den CAD-Dateien lasern (Makerspace in der Umgebung ansteuern, z.B. [Chaosdorf Düsseldorf](https://wiki.chaosdorf.de/Lasercutter), [Das Labor in Bochum](https://wiki.das-labor.org/w/LABOR_Wiki)). Die einzelnen LEDs vom Strip schneiden und auf die Trägerplatte an den vorgezeichneten Stellen aufkleben (z.B. mit UHU Flüssigkleber). Dabei darauf achten, dass die LEDs innerhalb einer Zeile immer die gleiche Ausrichtung (+5V, Din/DO, GND) haben und die Ausrichtungen von Zeile zu Zeile entgegengesetzt sind.
|
||||
Die LEDs mit Drahtstücken verlöten, dabei darauf achten, dass alle Leitungen jeweils durchgängig verbunden sind (also alle +5V miteinander, alle GND, alle D) und nicht untereinander.
|
||||
Am Anfang den ESP anlöten:
|
||||
* 5V->+5V
|
||||
* G->GND
|
||||
* D1->Din (Pin-Benennung im Quelltext ist etwas anders)
|
||||
|
||||
### Material
|
||||
* 230 mm x 230 mm Pappe (schwarz) für Wortfolie
|
||||
- -> [Wortfolie.dxf](cad-files/Wortfolie.dxf) verwenden
|
||||
* 230 mm x 230 mm Transparentpapier (z.B. für technisches Zeichnen) als Diffusor, alternativ weißes Backpapier
|
||||
* min 280 mm x 280 mm MDF für Trennwände
|
||||
- -> [Trennwaende_fuer_Laser.dxf](cad-files/Trennwaende_fuer_Laser.dxf) verwenden
|
||||
- Zahlen auf der linken Seite nach Möglichkeit nur gravieren oder weglassen
|
||||
* Rückwand der Rahmens (CAD-Datei ist passend für "RIBBA" von IKEA)
|
||||
- -> [Rueckwand-ohne-Gravuren.dxf](cad-files/Rueckwand-ohne-Gravuren.dxf) (alle Konturen außer der Umrandung ganz ausschneiden) **oder**
|
||||
- -> [Rueckwand-mit-Gravuren.dxf](cad-files/Rueckwand-mit-Gravuren.dxf) (LED-Markierungen und Pfeile nur mit einer Tiefe von ca. 0.2-0.5 mm gravieren) verwenden
|
||||
|
||||
|
||||
## Flashen
|
||||
|
||||
**Board und RTC wählen:** PlatformIO: Umgebung `<board>_<rtc>` mit Board `d1_mini` oder `nodemcu` und RTC `ds3231`, `ds1307` oder `keine` (z. B. `pio run -e nodemcu_ds3231 -t upload`). Arduino IDE: Board unter Werkzeuge wählen und oben in `arduino.ino` `RTC_MODUL_DS3231`, `RTC_MODUL_DS1307` oder `RTC_MODUL_KEINE` definieren (Standard: DS3231). Die RTC hängt an D2 (SDA) / D1 (SCL); der DS1307 braucht 5 V.
|
||||
|
||||
1. Dieses Repo clonen (`git clone https://github.com/c3e/wordclock.git`)
|
||||
2. Die Arduino IDE installieren (https://www.arduino.cc/en/Main/Software)
|
||||
3. Die Datei `wordclock/wordclock.ino` in der Arduino IDE öffnen
|
||||
4. In der IDE unter Datei->Voreinstellungen->Zusätzliche Boardverwalter-URLs http://arduino.esp8266.com/stable/package_esp8266com_index.json hinzufügen
|
||||
5. Unter Werkzeuge->Boards->Boardverwalter nach "esp" suchen, esp8266 installieren
|
||||
6. Das richtige Board unter Werkzeuge->Boards aus wählen (z.B. WeMos D1 R1)
|
||||
7. Sketcch->Bibliothek einbinden->Bibliotheken verwalten
|
||||
8. Folgende installieren:
|
||||
* FastLED
|
||||
* WiFiManager
|
||||
* RTClib (Adafruit)
|
||||
9. Folgende Zip-Dateien herunterladen:
|
||||
* https://github.com/PaulStoffregen/Time/archive/master.zip
|
||||
* https://github.com/JChristensen/Timezone/archive/master.zip
|
||||
10. In der Arduino IDE unter Sketch->Bibliothek einbinden->.ZIP-Bibliothek hinzufügen die beiden heruntergeladenen .zip-Dateien auswählen
|
||||
11. Den "Kompilieren"-Haken oben links anklicken (die Warnungen bzgl. Architektur und bitbanging können ignoriert werden)
|
||||
12. Den ESP per USB anschließen
|
||||
13. Den "Hochladen"-Pfeil klicken, darauf warten, dass der Upload vollständig ist (wird in Konsole und Statuszeile ausgegeben)
|
||||
|
||||
## Inbetriebnahme
|
||||
|
||||
1. Strom anschließen, 5V, USB-Netzeil
|
||||
2. Ins WLAN `WordClock` verbinden
|
||||
2. Ins WLAN `WordClock` verbinden (Der Name kann im Quelltext verändert werden)
|
||||
3. Im Browser die IP `192.168.4.1` aufrufen
|
||||
4. WLAN auswählen und ggf. Passwort eingeben
|
||||
5. Nach dem Speichern der Einstellungen verschwindet das WLAN
|
||||
6. Uhr zeigt die Uhrzeit an
|
||||
|
||||
Wenn das WLAN (wird für den Empfang der Uhrzeit benötigt) nicht mehr auffindbar ist, wird das Konfigurations-WLAN unter `192.168.4.1` automatisch wieder aufgebaut. Um die Einstellungen von Hand zurückzusetzen:
|
||||
In der Arduino-IDE: Werkzeuge->Erase Flash->All Flash contents auswählen, dann den Programmcode erneut hochladen
|
||||
|
||||
## Design
|
||||
|
||||
Die Idee für das Design wurden vom FabLab Nürnberg übernommen. Die Firmware ist eine Eigenentwicklung.
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,127 @@
|
||||
{
|
||||
"board": {
|
||||
"active_layer": 0,
|
||||
"active_layer_preset": "",
|
||||
"auto_track_width": true,
|
||||
"hidden_netclasses": [],
|
||||
"hidden_nets": [],
|
||||
"high_contrast_mode": 0,
|
||||
"net_color_mode": 1,
|
||||
"opacity": {
|
||||
"images": 0.6,
|
||||
"pads": 1.0,
|
||||
"shapes": 1.0,
|
||||
"tracks": 1.0,
|
||||
"vias": 1.0,
|
||||
"zones": 0.6
|
||||
},
|
||||
"prototype_zone_fills": false,
|
||||
"selection_filter": {
|
||||
"dimensions": true,
|
||||
"footprints": true,
|
||||
"graphics": true,
|
||||
"keepouts": true,
|
||||
"lockedItems": false,
|
||||
"otherItems": true,
|
||||
"pads": true,
|
||||
"text": true,
|
||||
"tracks": true,
|
||||
"vias": true,
|
||||
"zones": true
|
||||
},
|
||||
"visible_items": [
|
||||
"vias",
|
||||
"footprint_text",
|
||||
"footprint_anchors",
|
||||
"ratsnest",
|
||||
"grid",
|
||||
"footprints_front",
|
||||
"footprints_back",
|
||||
"footprint_values",
|
||||
"footprint_references",
|
||||
"tracks",
|
||||
"drc_errors",
|
||||
"drawing_sheet",
|
||||
"bitmaps",
|
||||
"pads",
|
||||
"zones",
|
||||
"drc_warnings",
|
||||
"drc_exclusions",
|
||||
"locked_item_shadows",
|
||||
"conflict_shadows",
|
||||
"shapes",
|
||||
"board_outline_area",
|
||||
"ly_points"
|
||||
],
|
||||
"visible_layers": "ffffffff_ffffffff_ffffffff_ffffffff",
|
||||
"zone_display_mode": 0
|
||||
},
|
||||
"git": {
|
||||
"integration_disabled": false,
|
||||
"repo_type": "",
|
||||
"repo_username": "",
|
||||
"ssh_key": ""
|
||||
},
|
||||
"meta": {
|
||||
"filename": "Steuerungsplatine.kicad_prl",
|
||||
"version": 5
|
||||
},
|
||||
"net_inspector_panel": {
|
||||
"col_hidden": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"col_order": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9
|
||||
],
|
||||
"col_widths": [],
|
||||
"custom_group_rules": [],
|
||||
"expanded_rows": [],
|
||||
"filter_by_net_name": true,
|
||||
"filter_by_netclass": true,
|
||||
"filter_text": "",
|
||||
"group_by_constraint": false,
|
||||
"group_by_netclass": false,
|
||||
"show_time_domain_details": false,
|
||||
"show_unconnected_nets": false,
|
||||
"show_zero_pad_nets": false,
|
||||
"sort_ascending": true,
|
||||
"sorting_column": -1
|
||||
},
|
||||
"open_jobsets": [],
|
||||
"project": {
|
||||
"files": []
|
||||
},
|
||||
"schematic": {
|
||||
"hierarchy_collapsed": [],
|
||||
"selection_filter": {
|
||||
"graphics": true,
|
||||
"images": true,
|
||||
"labels": true,
|
||||
"lockedItems": false,
|
||||
"otherItems": true,
|
||||
"pins": true,
|
||||
"ruleAreas": true,
|
||||
"symbols": true,
|
||||
"text": true,
|
||||
"wires": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,680 @@
|
||||
{
|
||||
"board": {
|
||||
"3dviewports": [],
|
||||
"design_settings": {
|
||||
"defaults": {
|
||||
"apply_defaults_to_fp_barcodes": false,
|
||||
"apply_defaults_to_fp_dimensions": false,
|
||||
"apply_defaults_to_fp_fields": false,
|
||||
"apply_defaults_to_fp_shapes": false,
|
||||
"apply_defaults_to_fp_text": false,
|
||||
"board_outline_line_width": 0.05,
|
||||
"copper_line_width": 0.2,
|
||||
"copper_text_italic": false,
|
||||
"copper_text_size_h": 1.5,
|
||||
"copper_text_size_v": 1.5,
|
||||
"copper_text_thickness": 0.3,
|
||||
"copper_text_upright": false,
|
||||
"courtyard_line_width": 0.05,
|
||||
"dimension_precision": 4,
|
||||
"dimension_units": 3,
|
||||
"dimensions": {
|
||||
"arrow_length": 1270000,
|
||||
"extension_offset": 500000,
|
||||
"keep_text_aligned": true,
|
||||
"suppress_zeroes": true,
|
||||
"text_position": 0,
|
||||
"units_format": 0
|
||||
},
|
||||
"fab_line_width": 0.1,
|
||||
"fab_text_italic": false,
|
||||
"fab_text_size_h": 1.0,
|
||||
"fab_text_size_v": 1.0,
|
||||
"fab_text_thickness": 0.15,
|
||||
"fab_text_upright": false,
|
||||
"other_line_width": 0.1,
|
||||
"other_text_italic": false,
|
||||
"other_text_size_h": 1.0,
|
||||
"other_text_size_v": 1.0,
|
||||
"other_text_thickness": 0.15,
|
||||
"other_text_upright": false,
|
||||
"pads": {
|
||||
"drill": 0.8,
|
||||
"height": 1.27,
|
||||
"width": 1.27
|
||||
},
|
||||
"silk_line_width": 0.1,
|
||||
"silk_text_italic": false,
|
||||
"silk_text_size_h": 1.0,
|
||||
"silk_text_size_v": 1.0,
|
||||
"silk_text_thickness": 0.1,
|
||||
"silk_text_upright": false,
|
||||
"zones": {
|
||||
"border_display_style": 2,
|
||||
"border_hatch_pitch": 0.5,
|
||||
"corner_radius": 0.0,
|
||||
"corner_smoothing": 0,
|
||||
"fill_mode": 0,
|
||||
"hatch_gap": 1.5,
|
||||
"hatch_orientation": 0.0,
|
||||
"hatch_smoothing_level": 0,
|
||||
"hatch_smoothing_value": 0.1,
|
||||
"hatch_thickness": 1.0,
|
||||
"min_clearance": 0.5,
|
||||
"min_island_area": 10.0,
|
||||
"min_thickness": 0.25,
|
||||
"pad_connection": 1,
|
||||
"remove_islands": 0,
|
||||
"thermal_relief_gap": 0.5,
|
||||
"thermal_relief_spoke_width": 0.5
|
||||
}
|
||||
},
|
||||
"diff_pair_dimensions": [],
|
||||
"drc_exclusions": [],
|
||||
"meta": {
|
||||
"version": 2
|
||||
},
|
||||
"rule_severities": {
|
||||
"annular_width": "error",
|
||||
"clearance": "error",
|
||||
"connection_width": "warning",
|
||||
"copper_edge_clearance": "error",
|
||||
"copper_sliver": "warning",
|
||||
"courtyards_overlap": "error",
|
||||
"creepage": "error",
|
||||
"diff_pair_gap_out_of_range": "error",
|
||||
"diff_pair_uncoupled_length_too_long": "error",
|
||||
"drill_out_of_range": "error",
|
||||
"duplicate_footprints": "warning",
|
||||
"extra_footprint": "warning",
|
||||
"footprint": "error",
|
||||
"footprint_filters_mismatch": "ignore",
|
||||
"footprint_symbol_field_mismatch": "warning",
|
||||
"footprint_symbol_mismatch": "warning",
|
||||
"footprint_type_mismatch": "ignore",
|
||||
"hole_clearance": "error",
|
||||
"hole_to_hole": "warning",
|
||||
"holes_co_located": "warning",
|
||||
"invalid_outline": "error",
|
||||
"isolated_copper": "warning",
|
||||
"item_on_disabled_layer": "error",
|
||||
"items_not_allowed": "error",
|
||||
"length_out_of_range": "error",
|
||||
"lib_footprint_issues": "warning",
|
||||
"lib_footprint_mismatch": "warning",
|
||||
"malformed_courtyard": "error",
|
||||
"microvia_drill_out_of_range": "error",
|
||||
"mirrored_text_on_front_layer": "warning",
|
||||
"missing_courtyard": "ignore",
|
||||
"missing_footprint": "warning",
|
||||
"missing_tuning_profile": "warning",
|
||||
"net_conflict": "warning",
|
||||
"nonmirrored_text_on_back_layer": "warning",
|
||||
"npth_inside_courtyard": "error",
|
||||
"padstack": "warning",
|
||||
"pth_inside_courtyard": "error",
|
||||
"shorting_items": "error",
|
||||
"silk_edge_clearance": "warning",
|
||||
"silk_over_copper": "warning",
|
||||
"silk_overlap": "warning",
|
||||
"skew_out_of_range": "error",
|
||||
"solder_mask_bridge": "error",
|
||||
"starved_thermal": "error",
|
||||
"text_height": "warning",
|
||||
"text_on_edge_cuts": "error",
|
||||
"text_thickness": "warning",
|
||||
"through_hole_pad_without_hole": "error",
|
||||
"too_many_vias": "error",
|
||||
"track_angle": "error",
|
||||
"track_dangling": "warning",
|
||||
"track_not_centered_on_via": "ignore",
|
||||
"track_on_post_machined_layer": "error",
|
||||
"track_segment_length": "error",
|
||||
"track_width": "error",
|
||||
"tracks_crossing": "error",
|
||||
"tuning_profile_track_geometries": "ignore",
|
||||
"unconnected_items": "error",
|
||||
"unresolved_variable": "error",
|
||||
"via_dangling": "warning",
|
||||
"zones_intersect": "error"
|
||||
},
|
||||
"rules": {
|
||||
"max_error": 0.005,
|
||||
"min_clearance": 0.0,
|
||||
"min_connection": 0.0,
|
||||
"min_copper_edge_clearance": 0.5,
|
||||
"min_groove_width": 0.0,
|
||||
"min_hole_clearance": 0.25,
|
||||
"min_hole_to_hole": 0.25,
|
||||
"min_microvia_diameter": 0.2,
|
||||
"min_microvia_drill": 0.1,
|
||||
"min_resolved_spokes": 2,
|
||||
"min_silk_clearance": 0.0,
|
||||
"min_text_height": 0.8,
|
||||
"min_text_thickness": 0.08,
|
||||
"min_through_hole_diameter": 0.3,
|
||||
"min_track_width": 0.2,
|
||||
"min_via_annular_width": 0.1,
|
||||
"min_via_diameter": 0.5,
|
||||
"solder_mask_to_copper_clearance": 0.0,
|
||||
"use_height_for_length_calcs": true
|
||||
},
|
||||
"teardrop_options": [
|
||||
{
|
||||
"td_onpthpad": true,
|
||||
"td_onroundshapesonly": false,
|
||||
"td_onsmdpad": true,
|
||||
"td_ontrackend": false,
|
||||
"td_onvia": true
|
||||
}
|
||||
],
|
||||
"teardrop_parameters": [
|
||||
{
|
||||
"td_allow_use_two_tracks": true,
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_on_pad_in_zone": false,
|
||||
"td_target_name": "td_round_shape",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
},
|
||||
{
|
||||
"td_allow_use_two_tracks": true,
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_on_pad_in_zone": false,
|
||||
"td_target_name": "td_rect_shape",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
},
|
||||
{
|
||||
"td_allow_use_two_tracks": true,
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_on_pad_in_zone": false,
|
||||
"td_target_name": "td_track_end",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
}
|
||||
],
|
||||
"track_widths": [],
|
||||
"tuning_pattern_settings": {
|
||||
"diff_pair_defaults": {
|
||||
"corner_radius_percentage": 80,
|
||||
"corner_style": 1,
|
||||
"max_amplitude": 1.0,
|
||||
"min_amplitude": 0.2,
|
||||
"single_sided": false,
|
||||
"spacing": 1.0
|
||||
},
|
||||
"diff_pair_skew_defaults": {
|
||||
"corner_radius_percentage": 80,
|
||||
"corner_style": 1,
|
||||
"max_amplitude": 1.0,
|
||||
"min_amplitude": 0.2,
|
||||
"single_sided": false,
|
||||
"spacing": 0.6
|
||||
},
|
||||
"single_track_defaults": {
|
||||
"corner_radius_percentage": 80,
|
||||
"corner_style": 1,
|
||||
"max_amplitude": 1.0,
|
||||
"min_amplitude": 0.2,
|
||||
"single_sided": false,
|
||||
"spacing": 0.6
|
||||
}
|
||||
},
|
||||
"via_dimensions": [],
|
||||
"zones_allow_external_fillets": false
|
||||
},
|
||||
"ipc2581": {
|
||||
"bom_rev": "",
|
||||
"dist": "",
|
||||
"distpn": "",
|
||||
"internal_id": "",
|
||||
"mfg": "",
|
||||
"mpn": "",
|
||||
"sch_revision": "26-1"
|
||||
},
|
||||
"layer_pairs": [],
|
||||
"layer_presets": [],
|
||||
"viewports": []
|
||||
},
|
||||
"boards": [],
|
||||
"component_class_settings": {
|
||||
"assignments": [],
|
||||
"meta": {
|
||||
"version": 0
|
||||
},
|
||||
"sheet_component_classes": {
|
||||
"enabled": false
|
||||
}
|
||||
},
|
||||
"cvpcb": {
|
||||
"equivalence_files": []
|
||||
},
|
||||
"erc": {
|
||||
"erc_exclusions": [],
|
||||
"meta": {
|
||||
"version": 0
|
||||
},
|
||||
"pin_map": [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
]
|
||||
],
|
||||
"rule_severities": {
|
||||
"bus_definition_conflict": "error",
|
||||
"bus_entry_needed": "error",
|
||||
"bus_to_bus_conflict": "error",
|
||||
"bus_to_net_conflict": "error",
|
||||
"different_unit_footprint": "error",
|
||||
"different_unit_net": "error",
|
||||
"duplicate_reference": "error",
|
||||
"duplicate_sheet_names": "error",
|
||||
"endpoint_off_grid": "warning",
|
||||
"extra_units": "error",
|
||||
"field_name_whitespace": "warning",
|
||||
"footprint_filter": "ignore",
|
||||
"footprint_link_issues": "warning",
|
||||
"four_way_junction": "ignore",
|
||||
"ground_pin_not_ground": "warning",
|
||||
"hier_label_mismatch": "error",
|
||||
"isolated_pin_label": "warning",
|
||||
"label_dangling": "error",
|
||||
"label_multiple_wires": "warning",
|
||||
"lib_symbol_issues": "warning",
|
||||
"lib_symbol_mismatch": "warning",
|
||||
"missing_bidi_pin": "warning",
|
||||
"missing_input_pin": "warning",
|
||||
"missing_power_pin": "error",
|
||||
"missing_unit": "warning",
|
||||
"multiple_net_names": "warning",
|
||||
"net_not_bus_member": "warning",
|
||||
"no_connect_connected": "warning",
|
||||
"no_connect_dangling": "warning",
|
||||
"pin_not_connected": "error",
|
||||
"pin_not_driven": "error",
|
||||
"pin_to_pin": "warning",
|
||||
"power_pin_not_driven": "error",
|
||||
"same_local_global_label": "warning",
|
||||
"similar_label_and_power": "warning",
|
||||
"similar_labels": "warning",
|
||||
"similar_power": "warning",
|
||||
"simulation_model_issue": "ignore",
|
||||
"single_global_label": "ignore",
|
||||
"stacked_pin_name": "warning",
|
||||
"unannotated": "error",
|
||||
"unconnected_wire_endpoint": "warning",
|
||||
"undefined_netclass": "error",
|
||||
"unit_value_mismatch": "error",
|
||||
"unresolved_variable": "error",
|
||||
"wire_dangling": "error"
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"pinned_footprint_libs": [],
|
||||
"pinned_symbol_libs": []
|
||||
},
|
||||
"meta": {
|
||||
"filename": "Steuerungsplatine.kicad_pro",
|
||||
"version": 3
|
||||
},
|
||||
"net_settings": {
|
||||
"classes": [
|
||||
{
|
||||
"bus_width": 12,
|
||||
"clearance": 0.2,
|
||||
"diff_pair_gap": 0.25,
|
||||
"diff_pair_via_gap": 0.25,
|
||||
"diff_pair_width": 0.2,
|
||||
"line_style": 0,
|
||||
"microvia_diameter": 0.3,
|
||||
"microvia_drill": 0.1,
|
||||
"name": "Default",
|
||||
"pcb_color": "rgba(0, 0, 0, 0.000)",
|
||||
"priority": 2147483647,
|
||||
"schematic_color": "rgba(0, 0, 0, 0.000)",
|
||||
"track_width": 0.2,
|
||||
"tuning_profile": "",
|
||||
"via_diameter": 0.6,
|
||||
"via_drill": 0.3,
|
||||
"wire_width": 6
|
||||
}
|
||||
],
|
||||
"meta": {
|
||||
"version": 5
|
||||
},
|
||||
"net_colors": null,
|
||||
"netclass_assignments": null,
|
||||
"netclass_patterns": []
|
||||
},
|
||||
"pcbnew": {
|
||||
"last_paths": {
|
||||
"idf": "",
|
||||
"netlist": "",
|
||||
"plot": "",
|
||||
"specctra_dsn": "",
|
||||
"step": "",
|
||||
"vrml": ""
|
||||
},
|
||||
"page_layout_descr_file": ""
|
||||
},
|
||||
"schematic": {
|
||||
"annotate_start_num": 0,
|
||||
"annotation": {
|
||||
"method": 0,
|
||||
"sort_order": 0
|
||||
},
|
||||
"bom_export_filename": "${PROJECTNAME}.csv",
|
||||
"bom_fmt_presets": [],
|
||||
"bom_fmt_settings": {
|
||||
"field_delimiter": ",",
|
||||
"keep_line_breaks": false,
|
||||
"keep_tabs": false,
|
||||
"name": "CSV",
|
||||
"ref_delimiter": ",",
|
||||
"ref_range_delimiter": "",
|
||||
"string_delimiter": "\""
|
||||
},
|
||||
"bom_presets": [],
|
||||
"bom_settings": {
|
||||
"exclude_dnp": false,
|
||||
"fields_ordered": [
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Reference",
|
||||
"name": "Reference",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Qty",
|
||||
"name": "${QUANTITY}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "Value",
|
||||
"name": "Value",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "DNP",
|
||||
"name": "${DNP}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "Exclude from BOM",
|
||||
"name": "${EXCLUDE_FROM_BOM}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "Exclude from Board",
|
||||
"name": "${EXCLUDE_FROM_BOARD}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "Exclude from Simulation",
|
||||
"name": "${EXCLUDE_FROM_SIM}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "Exclude from Position Files",
|
||||
"name": "${EXCLUDE_FROM_POS_FILES}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "Footprint",
|
||||
"name": "Footprint",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Datasheet",
|
||||
"name": "Datasheet",
|
||||
"show": true
|
||||
}
|
||||
],
|
||||
"filter_string": "",
|
||||
"group_symbols": true,
|
||||
"include_excluded_from_bom": true,
|
||||
"name": "Default Editing",
|
||||
"sort_asc": true,
|
||||
"sort_field": "Referenz"
|
||||
},
|
||||
"bus_aliases": {},
|
||||
"connection_grid_size": 50.0,
|
||||
"drawing": {
|
||||
"dashed_lines_dash_length_ratio": 12.0,
|
||||
"dashed_lines_gap_length_ratio": 3.0,
|
||||
"default_line_thickness": 6.0,
|
||||
"default_text_size": 50.0,
|
||||
"field_names": [],
|
||||
"hop_over_size_choice": 0,
|
||||
"intersheets_ref_own_page": false,
|
||||
"intersheets_ref_prefix": "",
|
||||
"intersheets_ref_short": false,
|
||||
"intersheets_ref_show": false,
|
||||
"intersheets_ref_suffix": "",
|
||||
"junction_size_choice": 3,
|
||||
"label_size_ratio": 0.375,
|
||||
"operating_point_overlay_i_precision": 3,
|
||||
"operating_point_overlay_i_range": "~A",
|
||||
"operating_point_overlay_v_precision": 3,
|
||||
"operating_point_overlay_v_range": "~V",
|
||||
"overbar_offset_ratio": 1.23,
|
||||
"pin_symbol_size": 25.0,
|
||||
"text_offset_ratio": 0.15
|
||||
},
|
||||
"legacy_lib_dir": "",
|
||||
"legacy_lib_list": [],
|
||||
"meta": {
|
||||
"version": 1
|
||||
},
|
||||
"page_layout_descr_file": "",
|
||||
"plot_directory": "",
|
||||
"reuse_designators": true,
|
||||
"subpart_first_id": 65,
|
||||
"subpart_id_separator": 0,
|
||||
"top_level_sheets": [
|
||||
{
|
||||
"filename": "Steuerungsplatine.kicad_sch",
|
||||
"name": "Steuerungsplatine",
|
||||
"uuid": "2236e95b-ee24-4f92-8cb3-ee17e346aa36"
|
||||
}
|
||||
],
|
||||
"used_designators": "",
|
||||
"variants": []
|
||||
},
|
||||
"sheets": [
|
||||
[
|
||||
"2236e95b-ee24-4f92-8cb3-ee17e346aa36",
|
||||
"Steuerungsplatine"
|
||||
]
|
||||
],
|
||||
"text_variables": {},
|
||||
"tuning_profiles": {
|
||||
"meta": {
|
||||
"version": 0
|
||||
},
|
||||
"tuning_profiles_impedance_geometric": []
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+94096
File diff suppressed because it is too large.
Load diff
Binary file not shown.
+94096
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Binary file not shown.
File diff suppressed because it is too large.
Load diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large.
Load diff
Binary file not shown.
File diff suppressed because it is too large.
Load diff
+1784230
File diff suppressed because it is too large.
Load diff
Binary file not shown.
+1784356
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
|
After Width: | Height: | Size: 1.1 MiB |
File diff suppressed because it is too large.
Load diff
|
After Width: | Height: | Size: 1.1 MiB |
File diff suppressed because it is too large.
Load diff
Binary file not shown.
File diff suppressed because it is too large.
Load diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large.
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1793844
File diff suppressed because it is too large.
Load diff
Binary file not shown.
Binary file not shown.
+100170
File diff suppressed because it is too large.
Load diff
+1704660
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,641 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <EEPROM.h>
|
||||
#include <time.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <Wire.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
// ================= RTC =================
|
||||
// RTC-Modul waehlen (vor dem Kompilieren): RTC_MODUL_DS3231, RTC_MODUL_DS1307 oder RTC_MODUL_KEINE.
|
||||
// PlatformIO: ueber die Umgebung (siehe platformio.ini). Arduino IDE: hier eintragen.
|
||||
// Das Board (D1 mini / NodeMCU) waehlt man in der IDE bzw. ebenfalls ueber die Umgebung;
|
||||
// die Pinnamen D1/D2/D4 sind bei beiden identisch.
|
||||
#if !defined(RTC_MODUL_DS3231) && !defined(RTC_MODUL_DS1307) && !defined(RTC_MODUL_KEINE)
|
||||
#define RTC_MODUL_DS3231
|
||||
#endif
|
||||
#if defined(RTC_MODUL_DS3231) || defined(RTC_MODUL_DS1307)
|
||||
#include <RTClib.h>
|
||||
#define RTC_VORHANDEN
|
||||
#endif
|
||||
#if defined(RTC_MODUL_DS3231)
|
||||
RTC_DS3231 rtc;
|
||||
#elif defined(RTC_MODUL_DS1307)
|
||||
RTC_DS1307 rtc;
|
||||
#endif
|
||||
#define RTC_SDA D2
|
||||
#define RTC_SCL D1
|
||||
bool rtcOk = false;
|
||||
bool rtcBatteryEmpty = false; // RTC hat beim Start die Zeit verloren
|
||||
volatile bool ntpJustSynced = false;
|
||||
void onTimeSet(bool fromSntp){ if(fromSntp) ntpJustSynced = true; }
|
||||
|
||||
// ================= LED =================
|
||||
#define LED_PIN D4
|
||||
// Neue Aufteilung (cad/openscad/gemeinsam.scad): je Wort ein LED-Streifen mit einer
|
||||
// LED pro Buchstabe, Zickzack durch die Zeilen. Zeile 0 laeuft links->rechts, Zeile 1
|
||||
// rechts->links usw. Die Fuellbuchstaben gibt es nicht, nur die Woerter (inkl. NTP,
|
||||
// API, RTC, ESP). Minutenpunkte sind abgeschaltet.
|
||||
#define NUMPIXELS 104
|
||||
Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// ================= SERVER & NTP =================
|
||||
ESP8266WebServer server(80);
|
||||
const char DEFAULT_NTP[] = "de.pool.ntp.org";
|
||||
const char DEFAULT_TZ[] = "CET-1CEST,M3.5.0/02,M10.5.0/03";
|
||||
String ntpServer = DEFAULT_NTP;
|
||||
String tzString = DEFAULT_TZ;
|
||||
|
||||
// ================= SETTINGS =================
|
||||
#define SETTINGS_MAGIC 0x57554853UL // erkennt gueltige EEPROM-Daten
|
||||
|
||||
struct Settings {
|
||||
uint32_t magic;
|
||||
int brightness;
|
||||
int nightBrightness;
|
||||
bool autoNight;
|
||||
int nightStart;
|
||||
int nightEnd;
|
||||
uint32_t color;
|
||||
uint32_t bgColor;
|
||||
bool backgroundMode;
|
||||
bool nightBackgroundDisabled;
|
||||
bool statusLeds;
|
||||
int ntpShowSec;
|
||||
char ntpServer[64];
|
||||
char tzString[64];
|
||||
} settings;
|
||||
|
||||
// ================= VAR =================
|
||||
uint32_t currentColor = 0x00FFFF;
|
||||
uint32_t bgColor = 0x000000;
|
||||
bool backgroundMode = false;
|
||||
bool nightBackgroundDisabled = false;
|
||||
bool statusLeds = true; // Statuswoerter NTP/RTC/ESP anzeigen
|
||||
int ntpShowSec = 10; // Mindestdauer der gruenen NTP-Anzeige
|
||||
bool forceInstant = false;
|
||||
bool updateNeeded = true;
|
||||
int brightness = 120;
|
||||
int nightBrightness = 10;
|
||||
bool autoNight = true;
|
||||
int nightStart = 22;
|
||||
int nightEnd = 6;
|
||||
uint32_t targetBuffer[NUMPIXELS]; // Soll-Farben (ohne Helligkeit/Gamma)
|
||||
uint32_t currentBuffer[NUMPIXELS]; // zuletzt angezeigte Soll-Farben
|
||||
int lastMinute = -1;
|
||||
int lastH = -1;
|
||||
|
||||
// ================= ZEIT =================
|
||||
bool timeSynced(){
|
||||
return time(nullptr) > 100000;
|
||||
}
|
||||
|
||||
// ================= EEPROM =================
|
||||
void saveSettings(){
|
||||
settings.magic = SETTINGS_MAGIC;
|
||||
settings.brightness = brightness;
|
||||
settings.nightBrightness = nightBrightness;
|
||||
settings.autoNight = autoNight;
|
||||
settings.nightStart = nightStart;
|
||||
settings.nightEnd = nightEnd;
|
||||
settings.color = currentColor;
|
||||
settings.bgColor = bgColor;
|
||||
settings.backgroundMode = backgroundMode;
|
||||
settings.nightBackgroundDisabled = nightBackgroundDisabled;
|
||||
settings.statusLeds = statusLeds;
|
||||
settings.ntpShowSec = ntpShowSec;
|
||||
strncpy(settings.ntpServer, ntpServer.c_str(), sizeof(settings.ntpServer) - 1);
|
||||
settings.ntpServer[sizeof(settings.ntpServer) - 1] = '\0';
|
||||
strncpy(settings.tzString, tzString.c_str(), sizeof(settings.tzString) - 1);
|
||||
settings.tzString[sizeof(settings.tzString) - 1] = '\0';
|
||||
EEPROM.put(0, settings);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
void loadSettings(){
|
||||
EEPROM.begin(512);
|
||||
EEPROM.get(0, settings);
|
||||
if(settings.magic == SETTINGS_MAGIC){
|
||||
brightness = constrain(settings.brightness, 0, 255);
|
||||
nightBrightness = constrain(settings.nightBrightness, 0, 255);
|
||||
autoNight = settings.autoNight;
|
||||
nightStart = constrain(settings.nightStart, 0, 23);
|
||||
nightEnd = constrain(settings.nightEnd, 0, 23);
|
||||
currentColor = settings.color & 0xFFFFFF;
|
||||
bgColor = settings.bgColor & 0xFFFFFF;
|
||||
backgroundMode = settings.backgroundMode;
|
||||
nightBackgroundDisabled = settings.nightBackgroundDisabled;
|
||||
statusLeds = settings.statusLeds;
|
||||
ntpShowSec = constrain(settings.ntpShowSec, 1, 60);
|
||||
settings.ntpServer[sizeof(settings.ntpServer) - 1] = '\0';
|
||||
settings.tzString[sizeof(settings.tzString) - 1] = '\0';
|
||||
ntpServer = String(settings.ntpServer);
|
||||
tzString = String(settings.tzString);
|
||||
if(ntpServer.length() == 0) ntpServer = DEFAULT_NTP;
|
||||
if(tzString.length() == 0) tzString = DEFAULT_TZ;
|
||||
}
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
}
|
||||
|
||||
// Zeit aus der RTC uebernehmen. Die RTC laeuft in UTC.
|
||||
#define RTC_INTERVAL_MS 3600000UL // ohne NTP: RTC stuendlich neu einlesen
|
||||
#define NTP_GUELTIG_MS 7200000UL // NTP-Sync gilt 2 h als aktuell
|
||||
unsigned long lastRtcReadMs = 0;
|
||||
unsigned long lastNtpMs = 0; // 0 = noch kein NTP-Sync seit Start
|
||||
bool ntpShowing = false; // NTP-Wort leuchtet gerade
|
||||
unsigned long ntpShowUntil = 0;
|
||||
|
||||
bool ntpAktuell(){
|
||||
return lastNtpMs != 0 && millis() - lastNtpMs < NTP_GUELTIG_MS;
|
||||
}
|
||||
|
||||
// Liest die RTC; liefert false, wenn sie keine gueltige Zeit hat (Batterie leer).
|
||||
bool readRtcToSystem(){
|
||||
#ifdef RTC_VORHANDEN
|
||||
lastRtcReadMs = millis();
|
||||
#if defined(RTC_MODUL_DS3231)
|
||||
bool valid = !rtc.lostPower();
|
||||
#else
|
||||
bool valid = rtc.isrunning();
|
||||
#endif
|
||||
DateTime n = rtc.now();
|
||||
if(valid && n.year() >= 2024){
|
||||
struct timeval tv = { (time_t)n.unixtime(), 0 };
|
||||
settimeofday(&tv, nullptr);
|
||||
ntpJustSynced = false; // der eigene Aufruf ist keine NTP-Zeit
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void initRtc(){
|
||||
#ifdef RTC_VORHANDEN
|
||||
Wire.begin(RTC_SDA, RTC_SCL);
|
||||
if(!rtc.begin()) return;
|
||||
rtcOk = true;
|
||||
// Nach dem Nachstellen per NTP ist der Batteriestatus nicht mehr erkennbar,
|
||||
// daher wird er nur beim Start bestimmt.
|
||||
rtcBatteryEmpty = !readRtcToSystem();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Nach jeder NTP-Synchronisation die RTC nachstellen; ohne aktuellen NTP-Sync
|
||||
// stuendlich die Systemzeit aus der RTC auffrischen.
|
||||
void updateTimeSources(){
|
||||
if(ntpJustSynced){
|
||||
ntpJustSynced = false;
|
||||
if(timeSynced()){
|
||||
lastNtpMs = millis() ? millis() : 1;
|
||||
ntpShowing = true;
|
||||
ntpShowUntil = millis() + (unsigned long)ntpShowSec * 1000UL;
|
||||
#ifdef RTC_VORHANDEN
|
||||
if(rtcOk) rtc.adjust(DateTime((uint32_t)time(nullptr)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if(ntpShowing && (long)(millis() - ntpShowUntil) >= 0) ntpShowing = false;
|
||||
#ifdef RTC_VORHANDEN
|
||||
if(rtcOk && !rtcBatteryEmpty && !ntpAktuell() && millis() - lastRtcReadMs >= RTC_INTERVAL_MS)
|
||||
readRtcToSystem();
|
||||
#endif
|
||||
}
|
||||
|
||||
// ================= STATUS-WOERTER =================
|
||||
// NTP (gruen): waehrend/kurz nach dem NTP-Abgleich
|
||||
// RTC (gelb): RTC vorhanden, aber kein aktueller NTP-Abgleich; bei leerer Batterie
|
||||
// blinkt das Wort im 10-s-Takt
|
||||
// ESP (rot): weder gueltige RTC noch NTP
|
||||
#define STATUS_GRUEN 0x00FF00
|
||||
#define STATUS_GELB 0xFFFF00
|
||||
#define STATUS_ROT 0xFF0000
|
||||
struct StatusFarben { uint32_t ntp, rtc, esp; };
|
||||
StatusFarben statusAktuell = {0, 0, 0};
|
||||
|
||||
StatusFarben berechneStatus(){
|
||||
StatusFarben st = {0, 0, 0};
|
||||
if(!statusLeds) return st;
|
||||
bool ntpOk = ntpAktuell();
|
||||
bool rtcGut = rtcOk && !rtcBatteryEmpty;
|
||||
if(ntpShowing) st.ntp = STATUS_GRUEN;
|
||||
if(rtcOk){
|
||||
if(rtcBatteryEmpty) st.rtc = ((millis() / 10000UL) & 1) ? 0 : STATUS_GELB;
|
||||
else if(!ntpOk) st.rtc = STATUS_GELB;
|
||||
}
|
||||
if(!rtcGut && !ntpOk) st.esp = STATUS_ROT;
|
||||
return st;
|
||||
}
|
||||
|
||||
// Aenderung der Statusanzeige erkennen (loest ein Neuzeichnen aus)
|
||||
bool statusGeaendert(){
|
||||
StatusFarben st = berechneStatus();
|
||||
bool changed = st.ntp != statusAktuell.ntp || st.rtc != statusAktuell.rtc || st.esp != statusAktuell.esp;
|
||||
statusAktuell = st;
|
||||
return changed;
|
||||
}
|
||||
|
||||
void applyStatus(){
|
||||
for(int i=34;i<=36;i++) if(statusAktuell.ntp) targetBuffer[i] = statusAktuell.ntp;
|
||||
for(int i=56;i<=58;i++) if(statusAktuell.rtc) targetBuffer[i] = statusAktuell.rtc;
|
||||
for(int i=67;i<=69;i++) if(statusAktuell.esp) targetBuffer[i] = statusAktuell.esp;
|
||||
}
|
||||
|
||||
// ================= HELFER =================
|
||||
bool isNightTime(struct tm *t){
|
||||
if(!autoNight) return false;
|
||||
int h = t->tm_hour;
|
||||
if(nightStart > nightEnd){
|
||||
return (h >= nightStart || h < nightEnd);
|
||||
} else {
|
||||
return (h >= nightStart && h < nightEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void setRange(int a,int b){
|
||||
for(int i=a;i<=b;i++) targetBuffer[i]=currentColor;
|
||||
}
|
||||
|
||||
uint32_t blend(uint32_t c1, uint32_t c2, float t){
|
||||
uint8_t r1=(c1>>16)&255, g1=(c1>>8)&255, b1=c1&255;
|
||||
uint8_t r2=(c2>>16)&255, g2=(c2>>8)&255, b2=c2&255;
|
||||
return pixels.Color((uint8_t)(r1+(r2-r1)*t + 0.5f),
|
||||
(uint8_t)(g1+(g2-g1)*t + 0.5f),
|
||||
(uint8_t)(b1+(b2-b1)*t + 0.5f));
|
||||
}
|
||||
|
||||
uint8_t gamma8(uint8_t x){
|
||||
float f = (float)x / 255.0f;
|
||||
return (uint8_t)(f * f * 255.0f + 0.5f);
|
||||
}
|
||||
|
||||
// Skaliert einen Farbkanal mit der Helligkeit und korrigiert Gamma.
|
||||
// Ein aktiver Kanal bleibt bei Helligkeit > 0 mindestens auf 1, damit er nicht erlischt.
|
||||
uint8_t scaleChannel(uint8_t c, float factor){
|
||||
if(c == 0 || factor <= 0) return 0;
|
||||
uint8_t v = gamma8((uint8_t)(c * factor));
|
||||
return v ? v : 1;
|
||||
}
|
||||
|
||||
uint32_t applyGammaBrightness(uint32_t c, float brightnessFactor){
|
||||
return pixels.Color(scaleChannel((c >> 16) & 255, brightnessFactor),
|
||||
scaleChannel((c >> 8) & 255, brightnessFactor),
|
||||
scaleChannel(c & 255, brightnessFactor));
|
||||
}
|
||||
|
||||
int getBrightness(struct tm *t){
|
||||
return isNightTime(t) ? nightBrightness : brightness;
|
||||
}
|
||||
|
||||
void showInstant(){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
float b = getBrightness(t) / 255.0f;
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
pixels.setPixelColor(i, applyGammaBrightness(targetBuffer[i], b));
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void fadeToTargetSmooth(int steps = 30, int delayMs = 15){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
float bTarget = getBrightness(t) / 255.0f;
|
||||
|
||||
// Im Nachtmodus faden wir langsamer (mehr Schritte), um das Springen zu kaschieren
|
||||
if(isNightTime(t)){
|
||||
steps = 60;
|
||||
delayMs = 25;
|
||||
}
|
||||
|
||||
for(int s = 0; s <= steps; s++){
|
||||
float tBlend = (float)s / steps;
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
uint32_t c = blend(currentBuffer[i], targetBuffer[i], tBlend);
|
||||
pixels.setPixelColor(i, applyGammaBrightness(c, bTarget));
|
||||
}
|
||||
pixels.show();
|
||||
yield(); // Verhindert WDT-Reset beim ESP8266
|
||||
delay(delayMs);
|
||||
}
|
||||
}
|
||||
|
||||
// ================= WORTUHR LOGIK =================
|
||||
// LED-Indizes in Kettenreihenfolge (Zeilen im Zickzack, Woerter je Zeile in Laufrichtung)
|
||||
void word_ES(){ setRange(0,1); } // Zeile 0 (links->rechts)
|
||||
void word_IST(){ setRange(2,4); }
|
||||
void word_FUENF_M(){ setRange(5,8); }
|
||||
void word_ZEHN_M(){ setRange(9,12); } // Zeile 1 (rechts->links)
|
||||
void word_ZWANZIG(){ setRange(13,19); }
|
||||
void word_VIERTEL(){ setRange(20,26); } // Zeile 2
|
||||
void word_VOR(){ setRange(27,29); }
|
||||
void word_NACH(){ setRange(30,33); } // Zeile 3 (rechts->links)
|
||||
// NTP 34-36
|
||||
void word_HALB(){ setRange(37,40); }
|
||||
void word_NEUN(){ setRange(41,44); } // Zeile 4
|
||||
// API 45-47
|
||||
void word_FUENF_H(){ setRange(48,51); }
|
||||
void word_EINS(){ setRange(52,55); } // Zeile 5 (rechts->links): S, EIN, RTC, ZWEI
|
||||
void word_EIN(){ setRange(53,55); }
|
||||
// RTC 56-58
|
||||
void word_ZWEI(){ setRange(59,62); }
|
||||
void word_DREI(){ setRange(63,66); } // Zeile 6
|
||||
// ESP 67-69
|
||||
void word_VIER(){ setRange(70,73); }
|
||||
void word_SECHS(){ setRange(74,78); } // Zeile 7 (rechts->links)
|
||||
void word_ACHT(){ setRange(79,82); }
|
||||
void word_SIEBEN(){ setRange(83,88); } // Zeile 8
|
||||
void word_ZWOELF(){ setRange(89,93); }
|
||||
void word_ZEHN_H(){ setRange(94,97); } // Zeile 9 (rechts->links)
|
||||
void word_ELF(){ setRange(98,100); }
|
||||
void word_UHR(){ setRange(101,103); }
|
||||
|
||||
String getTimeText(int h, int m){
|
||||
int m5 = (m/5)*5;
|
||||
if(m5 >= 25) h++;
|
||||
const char* arr[] = {"Zwölf","Eins","Zwei","Drei","Vier","Fünf","Sechs","Sieben","Acht","Neun","Zehn","Elf"};
|
||||
String hName = arr[h%12];
|
||||
String t = "Es ist ";
|
||||
switch(m5){
|
||||
case 0: t += (h%12 == 1) ? String("ein") : hName; t += " Uhr"; break;
|
||||
case 5: t += "fünf nach " + hName; break;
|
||||
case 10: t += "zehn nach " + hName; break;
|
||||
case 15: t += "viertel nach " + hName; break;
|
||||
case 20: t += "zwanzig nach " + hName; break;
|
||||
case 25: t += "fünf vor halb " + hName; break;
|
||||
case 30: t += "halb " + hName; break;
|
||||
case 35: t += "fünf nach halb " + hName; break;
|
||||
case 40: t += "zwanzig vor " + hName; break;
|
||||
case 45: t += "viertel vor " + hName; break;
|
||||
case 50: t += "zehn vor " + hName; break;
|
||||
case 55: t += "fünf vor " + hName; break;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void showTimeWords(int h, int m){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
// Startpunkt des Fades ist die zuletzt angezeigte Soll-Farbe (ohne Helligkeit/Gamma)
|
||||
for(int i=0;i<NUMPIXELS;i++) currentBuffer[i] = targetBuffer[i];
|
||||
|
||||
// Hintergrund mit Nacht-Aus-Option
|
||||
uint32_t activeBg = 0;
|
||||
if(backgroundMode && !(nightBackgroundDisabled && isNightTime(t))){
|
||||
activeBg = bgColor;
|
||||
}
|
||||
for(int i=0;i<NUMPIXELS;i++) targetBuffer[i] = activeBg;
|
||||
|
||||
word_ES(); word_IST();
|
||||
int m5 = (m/5)*5; bool full = (m5 == 0); if(m5 >= 25) h++;
|
||||
switch(m5){
|
||||
case 0: word_UHR(); break;
|
||||
case 5: word_FUENF_M(); word_NACH(); break;
|
||||
case 10: word_ZEHN_M(); word_NACH(); break;
|
||||
case 15: word_VIERTEL(); word_NACH(); break;
|
||||
case 20: word_ZWANZIG(); word_NACH(); break;
|
||||
case 25: word_FUENF_M(); word_VOR(); word_HALB(); break;
|
||||
case 30: word_HALB(); break;
|
||||
case 35: word_FUENF_M(); word_NACH(); word_HALB(); break;
|
||||
case 40: word_ZWANZIG(); word_VOR(); break;
|
||||
case 45: word_VIERTEL(); word_VOR(); break;
|
||||
case 50: word_ZEHN_M(); word_VOR(); break;
|
||||
case 55: word_FUENF_M(); word_VOR(); break;
|
||||
}
|
||||
int hh = h % 12;
|
||||
if(hh == 1 && full) word_EIN();
|
||||
else if(hh == 1) word_EINS(); else if(hh == 2) word_ZWEI(); else if(hh == 3) word_DREI();
|
||||
else if(hh == 4) word_VIER(); else if(hh == 5) word_FUENF_H(); else if(hh == 6) word_SECHS();
|
||||
else if(hh == 7) word_SIEBEN(); else if(hh == 8) word_ACHT(); else if(hh == 9) word_NEUN();
|
||||
else if(hh == 10) word_ZEHN_H(); else if(hh == 11) word_ELF(); else word_ZWOELF();
|
||||
|
||||
applyStatus();
|
||||
|
||||
if(forceInstant){ showInstant(); forceInstant = false; }
|
||||
else { fadeToTargetSmooth(20, 10); }
|
||||
}
|
||||
|
||||
// Solange noch keine Zeit bekannt ist, nur Hintergrund und Statuswoerter zeigen
|
||||
void showStatusOnly(){
|
||||
for(int i=0;i<NUMPIXELS;i++) currentBuffer[i] = targetBuffer[i];
|
||||
uint32_t activeBg = backgroundMode ? bgColor : 0;
|
||||
for(int i=0;i<NUMPIXELS;i++) targetBuffer[i] = activeBg;
|
||||
applyStatus();
|
||||
showInstant();
|
||||
}
|
||||
|
||||
// ================= WEB HANDLERS =================
|
||||
String jsonEscape(const String &s){
|
||||
String out;
|
||||
for(unsigned int i = 0; i < s.length(); i++){
|
||||
char c = s[i];
|
||||
if(c == '"' || c == '\\'){ out += '\\'; out += c; }
|
||||
else if((uint8_t)c < 0x20) out += ' ';
|
||||
else out += c;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void sendOK(){ server.send(200, "text/plain", "OK"); }
|
||||
|
||||
// Liest den Parameter "val" als Zahl; sendet 400 und liefert false bei ungueltigem Wert.
|
||||
bool argInRange(int lo, int hi, int &out){
|
||||
if(!server.hasArg("val")){ server.send(400, "text/plain", "Fehlender Wert"); return false; }
|
||||
int v = server.arg("val").toInt();
|
||||
if(v < lo || v > hi){ server.send(400, "text/plain", "Ungueltiger Wert"); return false; }
|
||||
out = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
void handleStatus(){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
char hexCol[10], hexBg[10];
|
||||
snprintf(hexCol, sizeof(hexCol), "#%06X", (unsigned int)currentColor);
|
||||
snprintf(hexBg, sizeof(hexBg), "#%06X", (unsigned int)bgColor);
|
||||
String ntpStat = timeSynced() ? "OK" : "SYNC...";
|
||||
String json = "{";
|
||||
json += "\"txt\":\"" + (timeSynced() ? jsonEscape(getTimeText(t->tm_hour, t->tm_min)) : String("Warte auf Zeit...")) + "\",";
|
||||
json += "\"ip\":\"" + WiFi.localIP().toString() + "\",";
|
||||
json += "\"ntp\":\"" + ntpStat + "\",";
|
||||
json += "\"ntpServer\":\"" + jsonEscape(ntpServer) + "\",";
|
||||
json += "\"tzString\":\"" + jsonEscape(tzString) + "\",";
|
||||
json += "\"brightness\":" + String(brightness) + ",";
|
||||
json += "\"nightBrightness\":" + String(nightBrightness) + ",";
|
||||
json += "\"color\":\"" + String(hexCol) + "\",";
|
||||
json += "\"bgColor\":\"" + String(hexBg) + "\",";
|
||||
json += "\"night\":" + String(autoNight ? 1 : 0) + ",";
|
||||
json += "\"nightStart\":" + String(nightStart) + ",";
|
||||
json += "\"nightEnd\":" + String(nightEnd) + ",";
|
||||
json += "\"bg\":" + String(backgroundMode ? 1 : 0) + ",";
|
||||
json += "\"nightBgOff\":" + String(nightBackgroundDisabled ? 1 : 0) + ",";
|
||||
json += "\"statusLeds\":" + String(statusLeds ? 1 : 0) + ",";
|
||||
json += "\"ntpShowSec\":" + String(ntpShowSec);
|
||||
json += "}";
|
||||
server.send(200, "application/json", json);
|
||||
}
|
||||
|
||||
static const char INDEX_HTML[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE html>
|
||||
<html><head><meta charset='UTF-8'><meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<title>Wortuhr</title>
|
||||
<style>
|
||||
body{font-family:Arial,sans-serif; background:#fff; margin:0; color:#333; display:flex; flex-direction:column; align-items:center}
|
||||
.card{width:90%; max-width:400px; margin:10px; padding:15px; border-radius:12px; background:#f2f2f2; box-shadow: 0 2px 5px rgba(0,0,0,0.1); box-sizing:border-box}
|
||||
.big{font-size:26px; text-align:center; font-weight:bold; color:#0055ff}
|
||||
#status{font-size:0.85em; color:#666; text-align:center}
|
||||
input[type='range'], input[type='color'], input[type='text']{width:100%; margin-bottom:10px; box-sizing:border-box}
|
||||
button{width:100%; padding:12px; border-radius:8px; background:#0055ff; color:#fff; border:none; cursor:pointer}
|
||||
label{font-weight:bold; display:block; margin-bottom:5px}
|
||||
</style></head><body>
|
||||
<div class='card big' id='txt'>Lade...</div>
|
||||
<div class='card' id='status'>Verbinde...</div>
|
||||
<div class='card'>
|
||||
<label>Farbe Worte</label>
|
||||
<input type='color' id='col' onchange="f('/color?c='+this.value.substring(1))">
|
||||
<label>Helligkeit</label>
|
||||
<input type='range' id='br' min='0' max='255' oninput="f('/brightness?val='+this.value)">
|
||||
</div>
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='bg' onchange="f('/bg?val='+(this.checked?1:0))"> <b>Hintergrund</b><br><br>
|
||||
<input type='color' id='bgcol' onchange="f('/bgcolor?c='+this.value.substring(1))">
|
||||
</div>
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='night' onchange="f('/night?val='+(this.checked?1:0))"> <b>Nachtmodus</b><br><br>
|
||||
Von: <input type='number' id='nS' min='0' max='23' style='width:50px' oninput="n('/nightStart',this.value)"> Uhr
|
||||
Bis: <input type='number' id='nE' min='0' max='23' style='width:50px' oninput="n('/nightEnd',this.value)"> Uhr<br><br>
|
||||
<label>Nacht-Helligkeit</label>
|
||||
<input type='range' id='nbr' min='0' max='255' oninput="f('/nightBrightness?val='+this.value)">
|
||||
<input type='checkbox' id='nightBgOff' onchange="f('/nightBgOff?val='+(this.checked?1:0))"> Hintergrund in Nacht aus
|
||||
</div>
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='sl' onchange="f('/statusLeds?val='+(this.checked?1:0))"> <b>Status-Anzeige</b> (NTP grün, RTC gelb, ESP rot)<br><br>
|
||||
NTP-Anzeige mind. <input type='number' id='nsec' min='1' max='60' style='width:50px' oninput="if(this.value!=='')f('/ntpShowSec?val='+this.value)"> Sekunden
|
||||
</div>
|
||||
<div class='card'>
|
||||
<label>NTP Server:</label>
|
||||
<input type='text' id='ntpS' onchange="f('/setNTP?val='+encodeURIComponent(this.value))">
|
||||
<label>Zeitzone (POSIX TZ):</label>
|
||||
<input type='text' id='tzS' onchange="f('/setTZ?val='+encodeURIComponent(this.value))">
|
||||
</div>
|
||||
<div class='card'><button onclick="f('/save').then(()=>alert('Gespeichert!'))">EEPROM Speichern</button></div>
|
||||
<script>
|
||||
function f(u){return fetch(u)}
|
||||
function n(u,v){ if(v==='') return; f(u+'?val='+Math.min(23,Math.max(0,parseInt(v)||0))); }
|
||||
function u(){fetch('/status').then(r=>r.json()).then(d=>{
|
||||
document.getElementById('txt').innerText=d.txt;
|
||||
document.getElementById('status').innerText="IP: "+d.ip+" | NTP: "+d.ntp;
|
||||
const s=(i,v,c=false)=>{const e=document.getElementById(i);if(e&&document.activeElement!==e){if(c)e.checked=(v==1);else e.value=v;}};
|
||||
s('col',d.color);s('br',d.brightness);s('night',d.night,true);s('nS',d.nightStart);s('nE',d.nightEnd);
|
||||
s('nbr',d.nightBrightness);s('bg',d.bg,true);s('bgcol',d.bgColor);s('ntpS',d.ntpServer);s('tzS',d.tzString);
|
||||
s('nightBgOff',d.nightBgOff,true);s('sl',d.statusLeds,true);s('nsec',d.ntpShowSec);
|
||||
}).catch(()=>{document.getElementById('status').innerText='Verbindung unterbrochen...';})}
|
||||
setInterval(u, 2500); u();
|
||||
</script></body></html>
|
||||
)rawliteral";
|
||||
|
||||
void handleRoot(){
|
||||
server.send_P(200, "text/html", INDEX_HTML);
|
||||
}
|
||||
|
||||
void handleColor(){
|
||||
if(server.hasArg("c")){
|
||||
currentColor = strtoul(server.arg("c").c_str(), NULL, 16) & 0xFFFFFF;
|
||||
forceInstant = true; updateNeeded = true;
|
||||
}
|
||||
sendOK();
|
||||
}
|
||||
void handleBGColor(){
|
||||
if(server.hasArg("c")){
|
||||
bgColor = strtoul(server.arg("c").c_str(), NULL, 16) & 0xFFFFFF;
|
||||
forceInstant = true; updateNeeded = true;
|
||||
}
|
||||
sendOK();
|
||||
}
|
||||
void handleBrightness(){ int v; if(!argInRange(0,255,v)) return; brightness=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNight(){ int v; if(!argInRange(0,1,v)) return; autoNight=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightStart(){ int v; if(!argInRange(0,23,v)) return; nightStart=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightEnd(){ int v; if(!argInRange(0,23,v)) return; nightEnd=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightBrightness(){ int v; if(!argInRange(0,255,v)) return; nightBrightness=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightBgOff(){ int v; if(!argInRange(0,1,v)) return; nightBackgroundDisabled=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleStatusLeds(){ int v; if(!argInRange(0,1,v)) return; statusLeds=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNtpShowSec(){ int v; if(!argInRange(1,60,v)) return; ntpShowSec=v; sendOK(); }
|
||||
void handleBG(){ int v; if(!argInRange(0,1,v)) return; backgroundMode=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
|
||||
void handleNTP(){
|
||||
String v = server.arg("val"); v.trim();
|
||||
if(v.length() == 0 || v.length() >= sizeof(settings.ntpServer)){ server.send(400, "text/plain", "Ungueltiger Wert"); return; }
|
||||
ntpServer = v;
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
sendOK();
|
||||
}
|
||||
void handleTZ(){
|
||||
String v = server.arg("val"); v.trim();
|
||||
if(v.length() == 0 || v.length() >= sizeof(settings.tzString)){ server.send(400, "text/plain", "Ungueltiger Wert"); return; }
|
||||
tzString = v;
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
sendOK();
|
||||
}
|
||||
void handleSave(){ saveSettings(); sendOK(); }
|
||||
|
||||
// ================= SETUP & LOOP =================
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
pixels.show();
|
||||
|
||||
settimeofday_cb(onTimeSet);
|
||||
loadSettings();
|
||||
initRtc();
|
||||
|
||||
WiFiManager wm;
|
||||
wm.autoConnect("Wortuhr");
|
||||
|
||||
server.on("/", handleRoot);
|
||||
server.on("/status", handleStatus);
|
||||
server.on("/color", handleColor);
|
||||
server.on("/bgcolor", handleBGColor);
|
||||
server.on("/brightness", handleBrightness);
|
||||
server.on("/night", handleNight);
|
||||
server.on("/nightStart", handleNightStart);
|
||||
server.on("/nightEnd", handleNightEnd);
|
||||
server.on("/nightBrightness", handleNightBrightness);
|
||||
server.on("/nightBgOff", handleNightBgOff);
|
||||
server.on("/bg", handleBG);
|
||||
server.on("/statusLeds", handleStatusLeds);
|
||||
server.on("/ntpShowSec", handleNtpShowSec);
|
||||
server.on("/setNTP", handleNTP);
|
||||
server.on("/setTZ", handleTZ);
|
||||
server.on("/save", handleSave);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
server.handleClient();
|
||||
updateTimeSources();
|
||||
if(statusGeaendert()){ forceInstant = true; updateNeeded = true; }
|
||||
|
||||
// Ohne bekannte Zeit nur die Statuswoerter anzeigen
|
||||
if(!timeSynced()){
|
||||
if(updateNeeded){ updateNeeded = false; forceInstant = false; showStatusOnly(); }
|
||||
return;
|
||||
}
|
||||
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
int currentM5 = (t->tm_min / 5) * 5;
|
||||
if(currentM5 != lastMinute || t->tm_hour != lastH){
|
||||
lastMinute = currentM5;
|
||||
lastH = t->tm_hour;
|
||||
updateNeeded = true;
|
||||
}
|
||||
|
||||
if(updateNeeded){
|
||||
updateNeeded = false;
|
||||
showTimeWords(t->tm_hour, t->tm_min);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
.pio/
|
||||
@@ -0,0 +1,40 @@
|
||||
; Umgebung = Board + RTC-Modul waehlen, z.B.: pio run -e nodemcu_ds3231 -t upload
|
||||
; Board: d1_mini | nodemcu RTC: ds3231 | ds1307 | keine
|
||||
[common]
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
adafruit/Adafruit NeoPixel
|
||||
tzapu/WiFiManager
|
||||
adafruit/RTClib
|
||||
|
||||
[board_d1_mini]
|
||||
board = d1_mini
|
||||
|
||||
[board_nodemcu]
|
||||
board = nodemcuv2
|
||||
|
||||
[env:d1_mini_ds3231]
|
||||
extends = common, board_d1_mini
|
||||
build_flags = -DRTC_MODUL_DS3231
|
||||
|
||||
[env:d1_mini_ds1307]
|
||||
extends = common, board_d1_mini
|
||||
build_flags = -DRTC_MODUL_DS1307
|
||||
|
||||
[env:d1_mini_keine]
|
||||
extends = common, board_d1_mini
|
||||
build_flags = -DRTC_MODUL_KEINE
|
||||
|
||||
[env:nodemcu_ds3231]
|
||||
extends = common, board_nodemcu
|
||||
build_flags = -DRTC_MODUL_DS3231
|
||||
|
||||
[env:nodemcu_ds1307]
|
||||
extends = common, board_nodemcu
|
||||
build_flags = -DRTC_MODUL_DS1307
|
||||
|
||||
[env:nodemcu_keine]
|
||||
extends = common, board_nodemcu
|
||||
build_flags = -DRTC_MODUL_KEINE
|
||||
@@ -0,0 +1,641 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <EEPROM.h>
|
||||
#include <time.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <Wire.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
// ================= RTC =================
|
||||
// RTC-Modul waehlen (vor dem Kompilieren): RTC_MODUL_DS3231, RTC_MODUL_DS1307 oder RTC_MODUL_KEINE.
|
||||
// PlatformIO: ueber die Umgebung (siehe platformio.ini). Arduino IDE: hier eintragen.
|
||||
// Das Board (D1 mini / NodeMCU) waehlt man in der IDE bzw. ebenfalls ueber die Umgebung;
|
||||
// die Pinnamen D1/D2/D4 sind bei beiden identisch.
|
||||
#if !defined(RTC_MODUL_DS3231) && !defined(RTC_MODUL_DS1307) && !defined(RTC_MODUL_KEINE)
|
||||
#define RTC_MODUL_DS3231
|
||||
#endif
|
||||
#if defined(RTC_MODUL_DS3231) || defined(RTC_MODUL_DS1307)
|
||||
#include <RTClib.h>
|
||||
#define RTC_VORHANDEN
|
||||
#endif
|
||||
#if defined(RTC_MODUL_DS3231)
|
||||
RTC_DS3231 rtc;
|
||||
#elif defined(RTC_MODUL_DS1307)
|
||||
RTC_DS1307 rtc;
|
||||
#endif
|
||||
#define RTC_SDA D2
|
||||
#define RTC_SCL D1
|
||||
bool rtcOk = false;
|
||||
bool rtcBatteryEmpty = false; // RTC hat beim Start die Zeit verloren
|
||||
volatile bool ntpJustSynced = false;
|
||||
void onTimeSet(bool fromSntp){ if(fromSntp) ntpJustSynced = true; }
|
||||
|
||||
// ================= LED =================
|
||||
#define LED_PIN D4
|
||||
// Neue Aufteilung (cad/openscad/gemeinsam.scad): je Wort ein LED-Streifen mit einer
|
||||
// LED pro Buchstabe, Zickzack durch die Zeilen. Zeile 0 laeuft links->rechts, Zeile 1
|
||||
// rechts->links usw. Die Fuellbuchstaben gibt es nicht, nur die Woerter (inkl. NTP,
|
||||
// API, RTC, ESP). Minutenpunkte sind abgeschaltet.
|
||||
#define NUMPIXELS 104
|
||||
Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// ================= SERVER & NTP =================
|
||||
ESP8266WebServer server(80);
|
||||
const char DEFAULT_NTP[] = "de.pool.ntp.org";
|
||||
const char DEFAULT_TZ[] = "CET-1CEST,M3.5.0/02,M10.5.0/03";
|
||||
String ntpServer = DEFAULT_NTP;
|
||||
String tzString = DEFAULT_TZ;
|
||||
|
||||
// ================= SETTINGS =================
|
||||
#define SETTINGS_MAGIC 0x57554853UL // erkennt gueltige EEPROM-Daten
|
||||
|
||||
struct Settings {
|
||||
uint32_t magic;
|
||||
int brightness;
|
||||
int nightBrightness;
|
||||
bool autoNight;
|
||||
int nightStart;
|
||||
int nightEnd;
|
||||
uint32_t color;
|
||||
uint32_t bgColor;
|
||||
bool backgroundMode;
|
||||
bool nightBackgroundDisabled;
|
||||
bool statusLeds;
|
||||
int ntpShowSec;
|
||||
char ntpServer[64];
|
||||
char tzString[64];
|
||||
} settings;
|
||||
|
||||
// ================= VAR =================
|
||||
uint32_t currentColor = 0x00FFFF;
|
||||
uint32_t bgColor = 0x000000;
|
||||
bool backgroundMode = false;
|
||||
bool nightBackgroundDisabled = false;
|
||||
bool statusLeds = true; // Statuswoerter NTP/RTC/ESP anzeigen
|
||||
int ntpShowSec = 10; // Mindestdauer der gruenen NTP-Anzeige
|
||||
bool forceInstant = false;
|
||||
bool updateNeeded = true;
|
||||
int brightness = 120;
|
||||
int nightBrightness = 10;
|
||||
bool autoNight = true;
|
||||
int nightStart = 22;
|
||||
int nightEnd = 6;
|
||||
uint32_t targetBuffer[NUMPIXELS]; // Soll-Farben (ohne Helligkeit/Gamma)
|
||||
uint32_t currentBuffer[NUMPIXELS]; // zuletzt angezeigte Soll-Farben
|
||||
int lastMinute = -1;
|
||||
int lastH = -1;
|
||||
|
||||
// ================= ZEIT =================
|
||||
bool timeSynced(){
|
||||
return time(nullptr) > 100000;
|
||||
}
|
||||
|
||||
// ================= EEPROM =================
|
||||
void saveSettings(){
|
||||
settings.magic = SETTINGS_MAGIC;
|
||||
settings.brightness = brightness;
|
||||
settings.nightBrightness = nightBrightness;
|
||||
settings.autoNight = autoNight;
|
||||
settings.nightStart = nightStart;
|
||||
settings.nightEnd = nightEnd;
|
||||
settings.color = currentColor;
|
||||
settings.bgColor = bgColor;
|
||||
settings.backgroundMode = backgroundMode;
|
||||
settings.nightBackgroundDisabled = nightBackgroundDisabled;
|
||||
settings.statusLeds = statusLeds;
|
||||
settings.ntpShowSec = ntpShowSec;
|
||||
strncpy(settings.ntpServer, ntpServer.c_str(), sizeof(settings.ntpServer) - 1);
|
||||
settings.ntpServer[sizeof(settings.ntpServer) - 1] = '\0';
|
||||
strncpy(settings.tzString, tzString.c_str(), sizeof(settings.tzString) - 1);
|
||||
settings.tzString[sizeof(settings.tzString) - 1] = '\0';
|
||||
EEPROM.put(0, settings);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
void loadSettings(){
|
||||
EEPROM.begin(512);
|
||||
EEPROM.get(0, settings);
|
||||
if(settings.magic == SETTINGS_MAGIC){
|
||||
brightness = constrain(settings.brightness, 0, 255);
|
||||
nightBrightness = constrain(settings.nightBrightness, 0, 255);
|
||||
autoNight = settings.autoNight;
|
||||
nightStart = constrain(settings.nightStart, 0, 23);
|
||||
nightEnd = constrain(settings.nightEnd, 0, 23);
|
||||
currentColor = settings.color & 0xFFFFFF;
|
||||
bgColor = settings.bgColor & 0xFFFFFF;
|
||||
backgroundMode = settings.backgroundMode;
|
||||
nightBackgroundDisabled = settings.nightBackgroundDisabled;
|
||||
statusLeds = settings.statusLeds;
|
||||
ntpShowSec = constrain(settings.ntpShowSec, 1, 60);
|
||||
settings.ntpServer[sizeof(settings.ntpServer) - 1] = '\0';
|
||||
settings.tzString[sizeof(settings.tzString) - 1] = '\0';
|
||||
ntpServer = String(settings.ntpServer);
|
||||
tzString = String(settings.tzString);
|
||||
if(ntpServer.length() == 0) ntpServer = DEFAULT_NTP;
|
||||
if(tzString.length() == 0) tzString = DEFAULT_TZ;
|
||||
}
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
}
|
||||
|
||||
// Zeit aus der RTC uebernehmen. Die RTC laeuft in UTC.
|
||||
#define RTC_INTERVAL_MS 3600000UL // ohne NTP: RTC stuendlich neu einlesen
|
||||
#define NTP_GUELTIG_MS 7200000UL // NTP-Sync gilt 2 h als aktuell
|
||||
unsigned long lastRtcReadMs = 0;
|
||||
unsigned long lastNtpMs = 0; // 0 = noch kein NTP-Sync seit Start
|
||||
bool ntpShowing = false; // NTP-Wort leuchtet gerade
|
||||
unsigned long ntpShowUntil = 0;
|
||||
|
||||
bool ntpAktuell(){
|
||||
return lastNtpMs != 0 && millis() - lastNtpMs < NTP_GUELTIG_MS;
|
||||
}
|
||||
|
||||
// Liest die RTC; liefert false, wenn sie keine gueltige Zeit hat (Batterie leer).
|
||||
bool readRtcToSystem(){
|
||||
#ifdef RTC_VORHANDEN
|
||||
lastRtcReadMs = millis();
|
||||
#if defined(RTC_MODUL_DS3231)
|
||||
bool valid = !rtc.lostPower();
|
||||
#else
|
||||
bool valid = rtc.isrunning();
|
||||
#endif
|
||||
DateTime n = rtc.now();
|
||||
if(valid && n.year() >= 2024){
|
||||
struct timeval tv = { (time_t)n.unixtime(), 0 };
|
||||
settimeofday(&tv, nullptr);
|
||||
ntpJustSynced = false; // der eigene Aufruf ist keine NTP-Zeit
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void initRtc(){
|
||||
#ifdef RTC_VORHANDEN
|
||||
Wire.begin(RTC_SDA, RTC_SCL);
|
||||
if(!rtc.begin()) return;
|
||||
rtcOk = true;
|
||||
// Nach dem Nachstellen per NTP ist der Batteriestatus nicht mehr erkennbar,
|
||||
// daher wird er nur beim Start bestimmt.
|
||||
rtcBatteryEmpty = !readRtcToSystem();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Nach jeder NTP-Synchronisation die RTC nachstellen; ohne aktuellen NTP-Sync
|
||||
// stuendlich die Systemzeit aus der RTC auffrischen.
|
||||
void updateTimeSources(){
|
||||
if(ntpJustSynced){
|
||||
ntpJustSynced = false;
|
||||
if(timeSynced()){
|
||||
lastNtpMs = millis() ? millis() : 1;
|
||||
ntpShowing = true;
|
||||
ntpShowUntil = millis() + (unsigned long)ntpShowSec * 1000UL;
|
||||
#ifdef RTC_VORHANDEN
|
||||
if(rtcOk) rtc.adjust(DateTime((uint32_t)time(nullptr)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if(ntpShowing && (long)(millis() - ntpShowUntil) >= 0) ntpShowing = false;
|
||||
#ifdef RTC_VORHANDEN
|
||||
if(rtcOk && !rtcBatteryEmpty && !ntpAktuell() && millis() - lastRtcReadMs >= RTC_INTERVAL_MS)
|
||||
readRtcToSystem();
|
||||
#endif
|
||||
}
|
||||
|
||||
// ================= STATUS-WOERTER =================
|
||||
// NTP (gruen): waehrend/kurz nach dem NTP-Abgleich
|
||||
// RTC (gelb): RTC vorhanden, aber kein aktueller NTP-Abgleich; bei leerer Batterie
|
||||
// blinkt das Wort im 10-s-Takt
|
||||
// ESP (rot): weder gueltige RTC noch NTP
|
||||
#define STATUS_GRUEN 0x00FF00
|
||||
#define STATUS_GELB 0xFFFF00
|
||||
#define STATUS_ROT 0xFF0000
|
||||
struct StatusFarben { uint32_t ntp, rtc, esp; };
|
||||
StatusFarben statusAktuell = {0, 0, 0};
|
||||
|
||||
StatusFarben berechneStatus(){
|
||||
StatusFarben st = {0, 0, 0};
|
||||
if(!statusLeds) return st;
|
||||
bool ntpOk = ntpAktuell();
|
||||
bool rtcGut = rtcOk && !rtcBatteryEmpty;
|
||||
if(ntpShowing) st.ntp = STATUS_GRUEN;
|
||||
if(rtcOk){
|
||||
if(rtcBatteryEmpty) st.rtc = ((millis() / 10000UL) & 1) ? 0 : STATUS_GELB;
|
||||
else if(!ntpOk) st.rtc = STATUS_GELB;
|
||||
}
|
||||
if(!rtcGut && !ntpOk) st.esp = STATUS_ROT;
|
||||
return st;
|
||||
}
|
||||
|
||||
// Aenderung der Statusanzeige erkennen (loest ein Neuzeichnen aus)
|
||||
bool statusGeaendert(){
|
||||
StatusFarben st = berechneStatus();
|
||||
bool changed = st.ntp != statusAktuell.ntp || st.rtc != statusAktuell.rtc || st.esp != statusAktuell.esp;
|
||||
statusAktuell = st;
|
||||
return changed;
|
||||
}
|
||||
|
||||
void applyStatus(){
|
||||
for(int i=34;i<=36;i++) if(statusAktuell.ntp) targetBuffer[i] = statusAktuell.ntp;
|
||||
for(int i=56;i<=58;i++) if(statusAktuell.rtc) targetBuffer[i] = statusAktuell.rtc;
|
||||
for(int i=67;i<=69;i++) if(statusAktuell.esp) targetBuffer[i] = statusAktuell.esp;
|
||||
}
|
||||
|
||||
// ================= HELFER =================
|
||||
bool isNightTime(struct tm *t){
|
||||
if(!autoNight) return false;
|
||||
int h = t->tm_hour;
|
||||
if(nightStart > nightEnd){
|
||||
return (h >= nightStart || h < nightEnd);
|
||||
} else {
|
||||
return (h >= nightStart && h < nightEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void setRange(int a,int b){
|
||||
for(int i=a;i<=b;i++) targetBuffer[i]=currentColor;
|
||||
}
|
||||
|
||||
uint32_t blend(uint32_t c1, uint32_t c2, float t){
|
||||
uint8_t r1=(c1>>16)&255, g1=(c1>>8)&255, b1=c1&255;
|
||||
uint8_t r2=(c2>>16)&255, g2=(c2>>8)&255, b2=c2&255;
|
||||
return pixels.Color((uint8_t)(r1+(r2-r1)*t + 0.5f),
|
||||
(uint8_t)(g1+(g2-g1)*t + 0.5f),
|
||||
(uint8_t)(b1+(b2-b1)*t + 0.5f));
|
||||
}
|
||||
|
||||
uint8_t gamma8(uint8_t x){
|
||||
float f = (float)x / 255.0f;
|
||||
return (uint8_t)(f * f * 255.0f + 0.5f);
|
||||
}
|
||||
|
||||
// Skaliert einen Farbkanal mit der Helligkeit und korrigiert Gamma.
|
||||
// Ein aktiver Kanal bleibt bei Helligkeit > 0 mindestens auf 1, damit er nicht erlischt.
|
||||
uint8_t scaleChannel(uint8_t c, float factor){
|
||||
if(c == 0 || factor <= 0) return 0;
|
||||
uint8_t v = gamma8((uint8_t)(c * factor));
|
||||
return v ? v : 1;
|
||||
}
|
||||
|
||||
uint32_t applyGammaBrightness(uint32_t c, float brightnessFactor){
|
||||
return pixels.Color(scaleChannel((c >> 16) & 255, brightnessFactor),
|
||||
scaleChannel((c >> 8) & 255, brightnessFactor),
|
||||
scaleChannel(c & 255, brightnessFactor));
|
||||
}
|
||||
|
||||
int getBrightness(struct tm *t){
|
||||
return isNightTime(t) ? nightBrightness : brightness;
|
||||
}
|
||||
|
||||
void showInstant(){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
float b = getBrightness(t) / 255.0f;
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
pixels.setPixelColor(i, applyGammaBrightness(targetBuffer[i], b));
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void fadeToTargetSmooth(int steps = 30, int delayMs = 15){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
float bTarget = getBrightness(t) / 255.0f;
|
||||
|
||||
// Im Nachtmodus faden wir langsamer (mehr Schritte), um das Springen zu kaschieren
|
||||
if(isNightTime(t)){
|
||||
steps = 60;
|
||||
delayMs = 25;
|
||||
}
|
||||
|
||||
for(int s = 0; s <= steps; s++){
|
||||
float tBlend = (float)s / steps;
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
uint32_t c = blend(currentBuffer[i], targetBuffer[i], tBlend);
|
||||
pixels.setPixelColor(i, applyGammaBrightness(c, bTarget));
|
||||
}
|
||||
pixels.show();
|
||||
yield(); // Verhindert WDT-Reset beim ESP8266
|
||||
delay(delayMs);
|
||||
}
|
||||
}
|
||||
|
||||
// ================= WORTUHR LOGIK =================
|
||||
// LED-Indizes in Kettenreihenfolge (Zeilen im Zickzack, Woerter je Zeile in Laufrichtung)
|
||||
void word_ES(){ setRange(0,1); } // Zeile 0 (links->rechts)
|
||||
void word_IST(){ setRange(2,4); }
|
||||
void word_FUENF_M(){ setRange(5,8); }
|
||||
void word_ZEHN_M(){ setRange(9,12); } // Zeile 1 (rechts->links)
|
||||
void word_ZWANZIG(){ setRange(13,19); }
|
||||
void word_VIERTEL(){ setRange(20,26); } // Zeile 2
|
||||
void word_VOR(){ setRange(27,29); }
|
||||
void word_NACH(){ setRange(30,33); } // Zeile 3 (rechts->links)
|
||||
// NTP 34-36
|
||||
void word_HALB(){ setRange(37,40); }
|
||||
void word_NEUN(){ setRange(41,44); } // Zeile 4
|
||||
// API 45-47
|
||||
void word_FUENF_H(){ setRange(48,51); }
|
||||
void word_EINS(){ setRange(52,55); } // Zeile 5 (rechts->links): S, EIN, RTC, ZWEI
|
||||
void word_EIN(){ setRange(53,55); }
|
||||
// RTC 56-58
|
||||
void word_ZWEI(){ setRange(59,62); }
|
||||
void word_DREI(){ setRange(63,66); } // Zeile 6
|
||||
// ESP 67-69
|
||||
void word_VIER(){ setRange(70,73); }
|
||||
void word_SECHS(){ setRange(74,78); } // Zeile 7 (rechts->links)
|
||||
void word_ACHT(){ setRange(79,82); }
|
||||
void word_SIEBEN(){ setRange(83,88); } // Zeile 8
|
||||
void word_ZWOELF(){ setRange(89,93); }
|
||||
void word_ZEHN_H(){ setRange(94,97); } // Zeile 9 (rechts->links)
|
||||
void word_ELF(){ setRange(98,100); }
|
||||
void word_UHR(){ setRange(101,103); }
|
||||
|
||||
String getTimeText(int h, int m){
|
||||
int m5 = (m/5)*5;
|
||||
if(m5 >= 25) h++;
|
||||
const char* arr[] = {"Zwölf","Eins","Zwei","Drei","Vier","Fünf","Sechs","Sieben","Acht","Neun","Zehn","Elf"};
|
||||
String hName = arr[h%12];
|
||||
String t = "Es ist ";
|
||||
switch(m5){
|
||||
case 0: t += (h%12 == 1) ? String("ein") : hName; t += " Uhr"; break;
|
||||
case 5: t += "fünf nach " + hName; break;
|
||||
case 10: t += "zehn nach " + hName; break;
|
||||
case 15: t += "viertel nach " + hName; break;
|
||||
case 20: t += "zwanzig nach " + hName; break;
|
||||
case 25: t += "fünf vor halb " + hName; break;
|
||||
case 30: t += "halb " + hName; break;
|
||||
case 35: t += "fünf nach halb " + hName; break;
|
||||
case 40: t += "zwanzig vor " + hName; break;
|
||||
case 45: t += "viertel vor " + hName; break;
|
||||
case 50: t += "zehn vor " + hName; break;
|
||||
case 55: t += "fünf vor " + hName; break;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void showTimeWords(int h, int m){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
// Startpunkt des Fades ist die zuletzt angezeigte Soll-Farbe (ohne Helligkeit/Gamma)
|
||||
for(int i=0;i<NUMPIXELS;i++) currentBuffer[i] = targetBuffer[i];
|
||||
|
||||
// Hintergrund mit Nacht-Aus-Option
|
||||
uint32_t activeBg = 0;
|
||||
if(backgroundMode && !(nightBackgroundDisabled && isNightTime(t))){
|
||||
activeBg = bgColor;
|
||||
}
|
||||
for(int i=0;i<NUMPIXELS;i++) targetBuffer[i] = activeBg;
|
||||
|
||||
word_ES(); word_IST();
|
||||
int m5 = (m/5)*5; bool full = (m5 == 0); if(m5 >= 25) h++;
|
||||
switch(m5){
|
||||
case 0: word_UHR(); break;
|
||||
case 5: word_FUENF_M(); word_NACH(); break;
|
||||
case 10: word_ZEHN_M(); word_NACH(); break;
|
||||
case 15: word_VIERTEL(); word_NACH(); break;
|
||||
case 20: word_ZWANZIG(); word_NACH(); break;
|
||||
case 25: word_FUENF_M(); word_VOR(); word_HALB(); break;
|
||||
case 30: word_HALB(); break;
|
||||
case 35: word_FUENF_M(); word_NACH(); word_HALB(); break;
|
||||
case 40: word_ZWANZIG(); word_VOR(); break;
|
||||
case 45: word_VIERTEL(); word_VOR(); break;
|
||||
case 50: word_ZEHN_M(); word_VOR(); break;
|
||||
case 55: word_FUENF_M(); word_VOR(); break;
|
||||
}
|
||||
int hh = h % 12;
|
||||
if(hh == 1 && full) word_EIN();
|
||||
else if(hh == 1) word_EINS(); else if(hh == 2) word_ZWEI(); else if(hh == 3) word_DREI();
|
||||
else if(hh == 4) word_VIER(); else if(hh == 5) word_FUENF_H(); else if(hh == 6) word_SECHS();
|
||||
else if(hh == 7) word_SIEBEN(); else if(hh == 8) word_ACHT(); else if(hh == 9) word_NEUN();
|
||||
else if(hh == 10) word_ZEHN_H(); else if(hh == 11) word_ELF(); else word_ZWOELF();
|
||||
|
||||
applyStatus();
|
||||
|
||||
if(forceInstant){ showInstant(); forceInstant = false; }
|
||||
else { fadeToTargetSmooth(20, 10); }
|
||||
}
|
||||
|
||||
// Solange noch keine Zeit bekannt ist, nur Hintergrund und Statuswoerter zeigen
|
||||
void showStatusOnly(){
|
||||
for(int i=0;i<NUMPIXELS;i++) currentBuffer[i] = targetBuffer[i];
|
||||
uint32_t activeBg = backgroundMode ? bgColor : 0;
|
||||
for(int i=0;i<NUMPIXELS;i++) targetBuffer[i] = activeBg;
|
||||
applyStatus();
|
||||
showInstant();
|
||||
}
|
||||
|
||||
// ================= WEB HANDLERS =================
|
||||
String jsonEscape(const String &s){
|
||||
String out;
|
||||
for(unsigned int i = 0; i < s.length(); i++){
|
||||
char c = s[i];
|
||||
if(c == '"' || c == '\\'){ out += '\\'; out += c; }
|
||||
else if((uint8_t)c < 0x20) out += ' ';
|
||||
else out += c;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void sendOK(){ server.send(200, "text/plain", "OK"); }
|
||||
|
||||
// Liest den Parameter "val" als Zahl; sendet 400 und liefert false bei ungueltigem Wert.
|
||||
bool argInRange(int lo, int hi, int &out){
|
||||
if(!server.hasArg("val")){ server.send(400, "text/plain", "Fehlender Wert"); return false; }
|
||||
int v = server.arg("val").toInt();
|
||||
if(v < lo || v > hi){ server.send(400, "text/plain", "Ungueltiger Wert"); return false; }
|
||||
out = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
void handleStatus(){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
char hexCol[10], hexBg[10];
|
||||
snprintf(hexCol, sizeof(hexCol), "#%06X", (unsigned int)currentColor);
|
||||
snprintf(hexBg, sizeof(hexBg), "#%06X", (unsigned int)bgColor);
|
||||
String ntpStat = timeSynced() ? "OK" : "SYNC...";
|
||||
String json = "{";
|
||||
json += "\"txt\":\"" + (timeSynced() ? jsonEscape(getTimeText(t->tm_hour, t->tm_min)) : String("Warte auf Zeit...")) + "\",";
|
||||
json += "\"ip\":\"" + WiFi.localIP().toString() + "\",";
|
||||
json += "\"ntp\":\"" + ntpStat + "\",";
|
||||
json += "\"ntpServer\":\"" + jsonEscape(ntpServer) + "\",";
|
||||
json += "\"tzString\":\"" + jsonEscape(tzString) + "\",";
|
||||
json += "\"brightness\":" + String(brightness) + ",";
|
||||
json += "\"nightBrightness\":" + String(nightBrightness) + ",";
|
||||
json += "\"color\":\"" + String(hexCol) + "\",";
|
||||
json += "\"bgColor\":\"" + String(hexBg) + "\",";
|
||||
json += "\"night\":" + String(autoNight ? 1 : 0) + ",";
|
||||
json += "\"nightStart\":" + String(nightStart) + ",";
|
||||
json += "\"nightEnd\":" + String(nightEnd) + ",";
|
||||
json += "\"bg\":" + String(backgroundMode ? 1 : 0) + ",";
|
||||
json += "\"nightBgOff\":" + String(nightBackgroundDisabled ? 1 : 0) + ",";
|
||||
json += "\"statusLeds\":" + String(statusLeds ? 1 : 0) + ",";
|
||||
json += "\"ntpShowSec\":" + String(ntpShowSec);
|
||||
json += "}";
|
||||
server.send(200, "application/json", json);
|
||||
}
|
||||
|
||||
static const char INDEX_HTML[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE html>
|
||||
<html><head><meta charset='UTF-8'><meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<title>Wortuhr</title>
|
||||
<style>
|
||||
body{font-family:Arial,sans-serif; background:#fff; margin:0; color:#333; display:flex; flex-direction:column; align-items:center}
|
||||
.card{width:90%; max-width:400px; margin:10px; padding:15px; border-radius:12px; background:#f2f2f2; box-shadow: 0 2px 5px rgba(0,0,0,0.1); box-sizing:border-box}
|
||||
.big{font-size:26px; text-align:center; font-weight:bold; color:#0055ff}
|
||||
#status{font-size:0.85em; color:#666; text-align:center}
|
||||
input[type='range'], input[type='color'], input[type='text']{width:100%; margin-bottom:10px; box-sizing:border-box}
|
||||
button{width:100%; padding:12px; border-radius:8px; background:#0055ff; color:#fff; border:none; cursor:pointer}
|
||||
label{font-weight:bold; display:block; margin-bottom:5px}
|
||||
</style></head><body>
|
||||
<div class='card big' id='txt'>Lade...</div>
|
||||
<div class='card' id='status'>Verbinde...</div>
|
||||
<div class='card'>
|
||||
<label>Farbe Worte</label>
|
||||
<input type='color' id='col' onchange="f('/color?c='+this.value.substring(1))">
|
||||
<label>Helligkeit</label>
|
||||
<input type='range' id='br' min='0' max='255' oninput="f('/brightness?val='+this.value)">
|
||||
</div>
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='bg' onchange="f('/bg?val='+(this.checked?1:0))"> <b>Hintergrund</b><br><br>
|
||||
<input type='color' id='bgcol' onchange="f('/bgcolor?c='+this.value.substring(1))">
|
||||
</div>
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='night' onchange="f('/night?val='+(this.checked?1:0))"> <b>Nachtmodus</b><br><br>
|
||||
Von: <input type='number' id='nS' min='0' max='23' style='width:50px' oninput="n('/nightStart',this.value)"> Uhr
|
||||
Bis: <input type='number' id='nE' min='0' max='23' style='width:50px' oninput="n('/nightEnd',this.value)"> Uhr<br><br>
|
||||
<label>Nacht-Helligkeit</label>
|
||||
<input type='range' id='nbr' min='0' max='255' oninput="f('/nightBrightness?val='+this.value)">
|
||||
<input type='checkbox' id='nightBgOff' onchange="f('/nightBgOff?val='+(this.checked?1:0))"> Hintergrund in Nacht aus
|
||||
</div>
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='sl' onchange="f('/statusLeds?val='+(this.checked?1:0))"> <b>Status-Anzeige</b> (NTP grün, RTC gelb, ESP rot)<br><br>
|
||||
NTP-Anzeige mind. <input type='number' id='nsec' min='1' max='60' style='width:50px' oninput="if(this.value!=='')f('/ntpShowSec?val='+this.value)"> Sekunden
|
||||
</div>
|
||||
<div class='card'>
|
||||
<label>NTP Server:</label>
|
||||
<input type='text' id='ntpS' onchange="f('/setNTP?val='+encodeURIComponent(this.value))">
|
||||
<label>Zeitzone (POSIX TZ):</label>
|
||||
<input type='text' id='tzS' onchange="f('/setTZ?val='+encodeURIComponent(this.value))">
|
||||
</div>
|
||||
<div class='card'><button onclick="f('/save').then(()=>alert('Gespeichert!'))">EEPROM Speichern</button></div>
|
||||
<script>
|
||||
function f(u){return fetch(u)}
|
||||
function n(u,v){ if(v==='') return; f(u+'?val='+Math.min(23,Math.max(0,parseInt(v)||0))); }
|
||||
function u(){fetch('/status').then(r=>r.json()).then(d=>{
|
||||
document.getElementById('txt').innerText=d.txt;
|
||||
document.getElementById('status').innerText="IP: "+d.ip+" | NTP: "+d.ntp;
|
||||
const s=(i,v,c=false)=>{const e=document.getElementById(i);if(e&&document.activeElement!==e){if(c)e.checked=(v==1);else e.value=v;}};
|
||||
s('col',d.color);s('br',d.brightness);s('night',d.night,true);s('nS',d.nightStart);s('nE',d.nightEnd);
|
||||
s('nbr',d.nightBrightness);s('bg',d.bg,true);s('bgcol',d.bgColor);s('ntpS',d.ntpServer);s('tzS',d.tzString);
|
||||
s('nightBgOff',d.nightBgOff,true);s('sl',d.statusLeds,true);s('nsec',d.ntpShowSec);
|
||||
}).catch(()=>{document.getElementById('status').innerText='Verbindung unterbrochen...';})}
|
||||
setInterval(u, 2500); u();
|
||||
</script></body></html>
|
||||
)rawliteral";
|
||||
|
||||
void handleRoot(){
|
||||
server.send_P(200, "text/html", INDEX_HTML);
|
||||
}
|
||||
|
||||
void handleColor(){
|
||||
if(server.hasArg("c")){
|
||||
currentColor = strtoul(server.arg("c").c_str(), NULL, 16) & 0xFFFFFF;
|
||||
forceInstant = true; updateNeeded = true;
|
||||
}
|
||||
sendOK();
|
||||
}
|
||||
void handleBGColor(){
|
||||
if(server.hasArg("c")){
|
||||
bgColor = strtoul(server.arg("c").c_str(), NULL, 16) & 0xFFFFFF;
|
||||
forceInstant = true; updateNeeded = true;
|
||||
}
|
||||
sendOK();
|
||||
}
|
||||
void handleBrightness(){ int v; if(!argInRange(0,255,v)) return; brightness=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNight(){ int v; if(!argInRange(0,1,v)) return; autoNight=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightStart(){ int v; if(!argInRange(0,23,v)) return; nightStart=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightEnd(){ int v; if(!argInRange(0,23,v)) return; nightEnd=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightBrightness(){ int v; if(!argInRange(0,255,v)) return; nightBrightness=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNightBgOff(){ int v; if(!argInRange(0,1,v)) return; nightBackgroundDisabled=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleStatusLeds(){ int v; if(!argInRange(0,1,v)) return; statusLeds=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
void handleNtpShowSec(){ int v; if(!argInRange(1,60,v)) return; ntpShowSec=v; sendOK(); }
|
||||
void handleBG(){ int v; if(!argInRange(0,1,v)) return; backgroundMode=v; forceInstant=true; updateNeeded=true; sendOK(); }
|
||||
|
||||
void handleNTP(){
|
||||
String v = server.arg("val"); v.trim();
|
||||
if(v.length() == 0 || v.length() >= sizeof(settings.ntpServer)){ server.send(400, "text/plain", "Ungueltiger Wert"); return; }
|
||||
ntpServer = v;
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
sendOK();
|
||||
}
|
||||
void handleTZ(){
|
||||
String v = server.arg("val"); v.trim();
|
||||
if(v.length() == 0 || v.length() >= sizeof(settings.tzString)){ server.send(400, "text/plain", "Ungueltiger Wert"); return; }
|
||||
tzString = v;
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
sendOK();
|
||||
}
|
||||
void handleSave(){ saveSettings(); sendOK(); }
|
||||
|
||||
// ================= SETUP & LOOP =================
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
pixels.show();
|
||||
|
||||
settimeofday_cb(onTimeSet);
|
||||
loadSettings();
|
||||
initRtc();
|
||||
|
||||
WiFiManager wm;
|
||||
wm.autoConnect("Wortuhr");
|
||||
|
||||
server.on("/", handleRoot);
|
||||
server.on("/status", handleStatus);
|
||||
server.on("/color", handleColor);
|
||||
server.on("/bgcolor", handleBGColor);
|
||||
server.on("/brightness", handleBrightness);
|
||||
server.on("/night", handleNight);
|
||||
server.on("/nightStart", handleNightStart);
|
||||
server.on("/nightEnd", handleNightEnd);
|
||||
server.on("/nightBrightness", handleNightBrightness);
|
||||
server.on("/nightBgOff", handleNightBgOff);
|
||||
server.on("/bg", handleBG);
|
||||
server.on("/statusLeds", handleStatusLeds);
|
||||
server.on("/ntpShowSec", handleNtpShowSec);
|
||||
server.on("/setNTP", handleNTP);
|
||||
server.on("/setTZ", handleTZ);
|
||||
server.on("/save", handleSave);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
server.handleClient();
|
||||
updateTimeSources();
|
||||
if(statusGeaendert()){ forceInstant = true; updateNeeded = true; }
|
||||
|
||||
// Ohne bekannte Zeit nur die Statuswoerter anzeigen
|
||||
if(!timeSynced()){
|
||||
if(updateNeeded){ updateNeeded = false; forceInstant = false; showStatusOnly(); }
|
||||
return;
|
||||
}
|
||||
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
int currentM5 = (t->tm_min / 5) * 5;
|
||||
if(currentM5 != lastMinute || t->tm_hour != lastH){
|
||||
lastMinute = currentM5;
|
||||
lastH = t->tm_hour;
|
||||
updateNeeded = true;
|
||||
}
|
||||
|
||||
if(updateNeeded){
|
||||
updateNeeded = false;
|
||||
showTimeWords(t->tm_hour, t->tm_min);
|
||||
}
|
||||
}
|
||||
@@ -1,501 +0,0 @@
|
||||
/**
|
||||
* @file wordclock.ino
|
||||
* @author telegnom (ccc@telegnom.org)
|
||||
* @date 2019-02-23
|
||||
* @version 1.1
|
||||
*
|
||||
* @brief firmware for the c3e wordclock
|
||||
*
|
||||
* requires the time.h and timezone.h libraries
|
||||
* https://github.com/PaulStoffregen/Time/
|
||||
* https://github.com/JChristensen/Timezone/
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <FastLED.h>
|
||||
#include <TimeLib.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <Timezone.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
|
||||
#define NUM_LEDS 42
|
||||
#define DATA_PIN 5
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
|
||||
// NTP Servers:
|
||||
static const char ntpServerName[] = "pool.ntp.org";
|
||||
|
||||
// defining words
|
||||
|
||||
#define M_ES 0
|
||||
#define M_IST 1
|
||||
#define M_FUENF 2
|
||||
#define M_ZEHN 3
|
||||
#define M_VIERTEL 4
|
||||
#define M_VOR 5
|
||||
#define M_NACH 6
|
||||
#define M_HALB 7
|
||||
#define M_UHR 8
|
||||
#define H_EINS 9
|
||||
#define H_EIN 9
|
||||
#define H_ZWEI 10
|
||||
#define H_DREI 11
|
||||
#define H_VIER 12
|
||||
#define H_FUENF 13
|
||||
#define H_SECHS 14
|
||||
#define H_SIEBEN 15
|
||||
#define H_ACHT 16
|
||||
#define H_NEUN 17
|
||||
#define H_ZEHN 18
|
||||
#define H_ELF 19
|
||||
#define H_ZWOELF 20
|
||||
|
||||
TimeChangeRule myDST = {"CEST", Last, Sun, Mar, 2, 120}; //Daylight time = UTC - 4 hours
|
||||
TimeChangeRule mySTD = {"CET", Last, Sun, Oct, 2, 60}; //Standard time = UTC - 5 hours
|
||||
Timezone myTZ(myDST, mySTD);
|
||||
|
||||
int clockWords[21][10] = {
|
||||
{3,-1,-1,-1,-1,-1,-1,-1,-1,-1}, // es 0
|
||||
{2,-1,-1,-1,-1,-1,-1,-1,-1,-1}, // ist 1
|
||||
{0,1,-1,-1,-1,-1,-1,-1,-1,-1}, // fuenf 2
|
||||
{4,5,-1,-1,-1,-1,-1,-1,-1,-1}, // zehn 3
|
||||
{8,9,10,-1,-1,-1,-1,-1,-1,-1}, // viertel 4
|
||||
{11,12,-1,-1,-1,-1,-1,-1,-1,-1}, // vor 5
|
||||
{6,7,-1,-1,-1,-1,-1,-1,-1,-1}, // nach 6
|
||||
{13,14,-1,-1,-1,-1,-1,-1,-1,-1}, // halb 7
|
||||
{40,41,-1,-1,-1,-1,-1,-1,-1,-1}, // uhr 8
|
||||
{19,20,-1,-1,-1,-1,-1,-1,-1,-1}, // ein 9
|
||||
{21,22,-1,-1,-1,-1,-1,-1,-1,-1}, // zwei 10
|
||||
{25,26,-1,-1,-1,-1,-1,-1,-1,-1}, // drei 11
|
||||
{23,24,-1,-1,-1,-1,-1,-1,-1,-1}, // vier 12
|
||||
{15,16,-1,-1,-1,-1,-1,-1,-1,-1}, // fuenf 13
|
||||
{27,28,-1,-1,-1,-1,-1,-1,-1,-1}, // sechs 14
|
||||
{33,34,35,-1,-1,-1,-1,-1,-1,-1}, // sieben 15
|
||||
{29,30,-1,-1,-1,-1,-1,-1,-1,-1}, // acht 16
|
||||
{17,18,-1,-1,-1,-1,-1,-1,-1,-1}, // neun 17
|
||||
{36,37,-1,-1,-1,-1,-1,-1,-1,-1}, // zehn 18
|
||||
{38,39,-1,-1,-1,-1,-1,-1,-1,-1}, // elf 19
|
||||
{31,32,-1,-1,-1,-1,-1,-1,-1,-1}, // zwölf 20
|
||||
};
|
||||
|
||||
WiFiUDP Udp;
|
||||
unsigned int localPort = 8888; // local port to listen for UDP packets
|
||||
time_t getNtpTime();
|
||||
time_t loctime;
|
||||
uint8_t color = 0;
|
||||
int lastmin = 100;
|
||||
void printDigits(int digits);
|
||||
void sendNTPpacket(IPAddress &address);
|
||||
|
||||
void clear(bool show=true)
|
||||
{
|
||||
for(int i = 0; i<NUM_LEDS;i++) {
|
||||
leds[i] = 0x000000;
|
||||
}
|
||||
if (show) {
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
|
||||
void noWifi()
|
||||
{
|
||||
for(int i=0; i<NUM_LEDS; i++)
|
||||
{
|
||||
leds[i] = CHSV((255/(NUM_LEDS-1))*i, 255, 128);
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
|
||||
void printDigits(uint8_t digits, bool colon = true)
|
||||
{
|
||||
// utility for digital clock display: prints preceding colon and leading 0
|
||||
if (colon)
|
||||
{
|
||||
Serial.print(":");
|
||||
}
|
||||
if (digits < 10)
|
||||
Serial.print('0');
|
||||
Serial.print(digits);
|
||||
}
|
||||
|
||||
void digitalClockDisplay()
|
||||
{
|
||||
// digital clock display of the time
|
||||
printDigits((uint8_t) hour(loctime));
|
||||
printDigits((uint8_t) minute(loctime));
|
||||
printDigits((uint8_t) second(loctime));
|
||||
Serial.print(" ");
|
||||
Serial.print(day(loctime));
|
||||
Serial.print(".");
|
||||
Serial.print(month(loctime));
|
||||
Serial.print(".");
|
||||
Serial.print(year(loctime));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
|
||||
clear();
|
||||
Serial.begin(115200);
|
||||
WiFiManager wifiManager;
|
||||
while (!Serial) ; // Needed for Leonardo only
|
||||
delay(250);
|
||||
Serial.println("WordClock by telegnom");
|
||||
Serial.print("Setup Wifi ... ");
|
||||
wifiManager.autoConnect("WordClock");
|
||||
Serial.println('[ ok ]');
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
noWifi();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Serial.print("IP number assigned by DHCP is ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println("Starting UDP");
|
||||
Udp.begin(localPort);
|
||||
Serial.print("Local port: ");
|
||||
Serial.println(Udp.localPort());
|
||||
Serial.println("waiting for sync");
|
||||
setSyncProvider(getNtpTime);
|
||||
setSyncInterval(600);
|
||||
}
|
||||
|
||||
int prevDisplay = 100; // when the digital clock was displayed
|
||||
|
||||
void loop()
|
||||
{
|
||||
// time_t utc = now();
|
||||
loctime = myTZ.toLocal(now());
|
||||
if (timeStatus() != timeNotSet) {
|
||||
// if (prevDisplay != second(localtime))
|
||||
if (prevDisplay != second(loctime)) { //update the display only if time has changed
|
||||
prevDisplay = second(loctime);
|
||||
if (second()%10 == 0)
|
||||
{
|
||||
digitalClockDisplay();
|
||||
if (lastmin != minute(loctime))
|
||||
{
|
||||
setClock();
|
||||
}
|
||||
prevDisplay = second(loctime);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_word(int word, time_t current_time = loctime) {
|
||||
int wordlen = sizeof(clockWords[word])/sizeof(clockWords[word][0]);
|
||||
if (lastmin != minute(loctime))
|
||||
{
|
||||
color += 40;
|
||||
}
|
||||
for (int i=0; i<wordlen; i++)
|
||||
{
|
||||
if (clockWords[word][i] >= 0)
|
||||
{
|
||||
leds[clockWords[word][i]] = CHSV(color, 255, 128);
|
||||
Serial.print(clockWords[word][i]);
|
||||
Serial.print(" ");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setClock() {
|
||||
Serial.println("Updating display...");
|
||||
time_t current_time = loctime;
|
||||
clear(false);
|
||||
set_word(M_ES); // switch es on
|
||||
set_word(M_IST); // switch ist on
|
||||
getMinuteWord(); //get word for "minute"
|
||||
getHourWord(); // get word for hour
|
||||
FastLED.show(); //writing to led stipe
|
||||
lastmin = minute(loctime);
|
||||
Serial.println("... display updated.");
|
||||
}
|
||||
|
||||
int getHour()
|
||||
{
|
||||
int h = int(hour(loctime));
|
||||
int m = int(minute(loctime));
|
||||
/*
|
||||
get current hour if minute < 20
|
||||
Es ist viertel nach zehn
|
||||
get next hour if minute >=20
|
||||
Es ist zehn vor halb elf
|
||||
adjust hour to correct word around midnight:
|
||||
23:25 --> Es ist fuenf vor halb zwoelf
|
||||
*/
|
||||
Serial.println(m);
|
||||
if (m >= 20)
|
||||
{
|
||||
if (h < 23)
|
||||
{
|
||||
return h+1;
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
void getHourWord()
|
||||
{
|
||||
switch(getHour())
|
||||
{
|
||||
case 12:
|
||||
case 0:
|
||||
set_word(H_ZWOELF);
|
||||
Serial.println("zwoelf");
|
||||
break;
|
||||
case 1:
|
||||
case 13:
|
||||
// special case to get sigular @ "ein uhr"
|
||||
if (int(minute(loctime)) < 5)
|
||||
{
|
||||
set_word(H_EIN);
|
||||
Serial.println("ein");
|
||||
} else
|
||||
{
|
||||
set_word(H_EINS);
|
||||
Serial.println("eins");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 14:
|
||||
set_word(H_ZWEI);
|
||||
Serial.println("zwei");
|
||||
break;
|
||||
case 3:
|
||||
case 15:
|
||||
set_word(H_DREI);
|
||||
Serial.println("drei");
|
||||
break;
|
||||
case 4:
|
||||
case 16:
|
||||
set_word(H_VIER);
|
||||
Serial.println("vier");
|
||||
break;
|
||||
case 5:
|
||||
case 17:
|
||||
set_word(H_FUENF);
|
||||
Serial.println("fuenf");
|
||||
break;
|
||||
case 6:
|
||||
case 18:
|
||||
set_word(H_SECHS);
|
||||
Serial.println("sechs");
|
||||
break;
|
||||
case 7:
|
||||
case 19:
|
||||
set_word(H_SIEBEN);
|
||||
Serial.println("sieben");
|
||||
break;
|
||||
case 8:
|
||||
case 20:
|
||||
set_word(H_ACHT);
|
||||
Serial.println("acht");
|
||||
break;
|
||||
case 9:
|
||||
case 21:
|
||||
set_word(H_NEUN);
|
||||
Serial.println("neun");
|
||||
break;
|
||||
case 10:
|
||||
case 22:
|
||||
set_word(H_ZEHN);
|
||||
Serial.println("zehn");
|
||||
break;
|
||||
case 11:
|
||||
case 23:
|
||||
set_word(H_ELF);
|
||||
Serial.println("elf");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void getMinuteWord()
|
||||
{
|
||||
/*
|
||||
get word for current "minute"
|
||||
*/
|
||||
switch(int(minute(loctime)))
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
set_word(M_UHR);
|
||||
Serial.println("uhr");
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_NACH);
|
||||
Serial.println("fuenf nach");
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
set_word(M_ZEHN);
|
||||
set_word(M_NACH);
|
||||
Serial.println("zehn nach");
|
||||
break;
|
||||
case 15:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
set_word(M_VIERTEL);
|
||||
set_word(M_NACH);
|
||||
Serial.println("viertel nach");
|
||||
break;
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
set_word(M_ZEHN);
|
||||
set_word(M_VOR);
|
||||
set_word(M_HALB);
|
||||
Serial.println("zehn vor halb");
|
||||
break;
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_VOR);
|
||||
set_word(M_HALB);
|
||||
Serial.println("fuenf vor halb");
|
||||
break;
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
set_word(M_HALB);
|
||||
Serial.println("halb");
|
||||
break;
|
||||
case 35:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
case 39:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_NACH);
|
||||
set_word(M_HALB);
|
||||
Serial.println("fuenf nach halb");
|
||||
break;
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
set_word(M_ZEHN);
|
||||
set_word(M_NACH);
|
||||
set_word(M_HALB);
|
||||
Serial.println("zehn nach halb");
|
||||
break;
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
set_word(M_VIERTEL);
|
||||
set_word(M_VOR);
|
||||
Serial.println("viertel vor");
|
||||
break;
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 54:
|
||||
set_word(M_ZEHN);
|
||||
set_word(M_VOR);
|
||||
Serial.println("zehn vor");
|
||||
break;
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 59:
|
||||
case 60:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_VOR);
|
||||
Serial.println("fuenf vor");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------- NTP code ----------*/
|
||||
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
|
||||
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
|
||||
|
||||
time_t getNtpTime()
|
||||
{
|
||||
IPAddress ntpServerIP; // NTP server's ip address
|
||||
|
||||
while (Udp.parsePacket() > 0) ; // discard any previously received packets
|
||||
Serial.println("Transmit NTP Request");
|
||||
// get a random server from the pool
|
||||
WiFi.hostByName(ntpServerName, ntpServerIP);
|
||||
Serial.print(ntpServerName);
|
||||
Serial.print(": ");
|
||||
Serial.println(ntpServerIP);
|
||||
sendNTPpacket(ntpServerIP);
|
||||
uint32_t beginWait = millis();
|
||||
while (millis() - beginWait < 1500) {
|
||||
int size = Udp.parsePacket();
|
||||
if (size >= NTP_PACKET_SIZE) {
|
||||
Serial.println("Receive NTP Response");
|
||||
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
|
||||
unsigned long secsSince1900;
|
||||
// convert four bytes starting at location 40 to a long integer
|
||||
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
|
||||
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
|
||||
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
|
||||
secsSince1900 |= (unsigned long)packetBuffer[43];
|
||||
return secsSince1900 - 2208988800UL;
|
||||
}
|
||||
}
|
||||
Serial.println("No NTP Response :-(");
|
||||
return 0; // return 0 if unable to get the time
|
||||
}
|
||||
|
||||
// send an NTP request to the time server at the given address
|
||||
void sendNTPpacket(IPAddress &address)
|
||||
{
|
||||
// set all bytes in the buffer to 0
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
packetBuffer[1] = 0; // Stratum, or type of clock
|
||||
packetBuffer[2] = 6; // Polling Interval
|
||||
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[13] = 0x4E;
|
||||
packetBuffer[14] = 49;
|
||||
packetBuffer[15] = 52;
|
||||
Udp.beginPacket(address, 123); //NTP requests are to port 123
|
||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
Udp.endPacket();
|
||||
}
|
||||
Reference in new issue
Block a user