Untitled
unknown
plain_text
5 months ago
3.1 kB
2
Indexable
#include <stdio.h> // Standard Bibliothek für Ein- und Ausgabe #include <string.h> // Bibliothek für String-Operationen #include <stdlib.h> // Allgemeine Standard-Bibliothek #include <time.h> // Bibliothek für Zeitfunktionen #include <unistd.h> // Bibliothek für sleep() und andere Funktionen #include "sensehat.h" // Bibliothek für SenseHAT-Funktionen // Funktion, um ein Pixel an einer bestimmten Position (x, y) einzuschalten void schaltePixelEin(int x, int y) { // Überprüfen, ob die Position innerhalb der LED-Matrix liegt (0–7) if (x >= 0 && x < 8 && y >= 0 && y < 8) { // Abhängig von y die Farbe des Pixels einstellen if (y == 0) led_set_pixel(x, y, 0, 0, 128); // Blau else if (y == 1) led_set_pixel(x, y, 0, 128, 0); // Grün else if (y == 2) led_set_pixel(x, y, 128, 0, 0); // Rot else if (y == 3) led_set_pixel(x, y+1, 128, 128, 128); // Weiß else if (y == 4) led_set_pixel(x, y+1, 128, 200, 0); // Gelb else if (y == 5) led_set_pixel(x, y+1, 50, 50, 128); // Hellblau } } int main(void) { sensehat_init(); // SenseHAT initialisieren (wichtig vor der Nutzung) while (1) { // Endlosschleife für kontinuierliche Ausführung time_t t = time(NULL); // Aktuelle Zeit holen struct tm tm = *localtime(&t); // Zeit in lokale Zeit umwandeln // Zeitkomponenten extrahieren int y = (tm.tm_year + 1900) % 100; // Jahr (z. B. 2024 -> 24) int m = tm.tm_mon + 1; // Monat (1–12) int d = tm.tm_mday; // Tag des Monats (1–31) int h = tm.tm_hour; // Stunde (0–23) int mn = tm.tm_min; // Minute (0–59) int s = tm.tm_sec; // Sekunde (0–59) // Zeitkomponenten in ein Array speichern int tabValue[6] = {y, m, d, h, mn, s}; // Array für Jahr, Monat, Tag, Stunde, Minute, Sekunde int tabBin[7] = {1, 2, 4, 8, 16, 32, 64}; // Array für Binärwerte (1 bis 64) // LEDs für jede Zeitkomponente einschalten for (int j = 0; j < 6; j++) { // Schleife für die 6 Zeitkomponenten int value = tabValue[j]; // Aktuellen Wert holen (z. B. Jahr, Monat, ...) int i = 6; // Start bei der größten binären Position (64) // Den Wert in eine Binärdarstellung umrechnen while (value > 0 && i >= 0) { // Solange der Wert größer als 0 ist if (tabBin[i] <= value) { // Prüfen, ob der Binärwert passt value -= tabBin[i]; // Wert reduzieren schaltePixelEin(i, j); // Pixel an der Position (i, j) einschalten } else { i--; // Zur nächsten kleineren binären Position gehen } } } sleep(1); // 1 Sekunde warten led_clear(0, 0, 0); // Alle LEDs ausschalten } sensehat_close(); // SenseHAT deaktivieren (wichtig am Ende) return 0; }
Editor is loading...
Leave a Comment