01_Techniker_Projekt — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by frank-oenings.

Components

Sketch code

#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_NeoPixel.h>

#define LED_PIN        8   // Der Daten-Pin, an dem die Matrix hängt
#define MATRIX_WIDTH  16   // Physikalische Breite der Matrix
#define MATRIX_HEIGHT 16   // Physikalische Höhe der Matrix
#define NUM_LEDS      (MATRIX_WIDTH * MATRIX_HEIGHT)

Adafruit_NeoPixel matrix(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
RTC_DS3231 rtc;

// Farbdefinition (RGB)
const uint32_t FARBE_AN = matrix.Color(0, 0, 50); // Blau (nicht max. Helligkeit wegen Stromverbrauch)
const uint32_t FARBE_AUS = matrix.Color(0, 0, 0);

// Hilfsfunktion: Schaltet einen Buchstaben im 16x8 Raster ein (x: 0-15, y: 0-7)
void schalteBuchstabeEin(int x, int y) {
  // Da jeder Buchstabe 2 Pixel hoch ist, betrifft das zwei physikalische Y-Zeilen
  int physY1 = y * 2;
  int physY2 = (y * 2) + 1;

  int ledIndex1, ledIndex2;

  // Berechnung für das typische Zick-Zack-Layout der Matrix
  // Reihe 1 (physY1)
  if (physY1 % 2 == 0) {
    ledIndex1 = physY1 * MATRIX_WIDTH + x; // Von links nach rechts
  } else {
    ledIndex1 = physY1 * MATRIX_WIDTH + (MATRIX_WIDTH - 1 - x); // Von rechts nach links
  }

  // Reihe 2 (physY2)
  if (physY2 % 2 != 0) {
    ledIndex2 = physY2 * MATRIX_WIDTH + x;
  } else {
    ledIndex2 = physY2 * MATRIX_WIDTH + (MATRIX_WIDTH - 1 - x);
  }

  // Beide LEDs für diesen Buchstaben einschalten
  matrix.setPixelColor(ledIndex1, FARBE_AN);
  matrix.setPixelColor(ledIndex2, FARBE_AN);
}

// Hilfsfunktion: Schaltet ein ganzes Wort anhand von Start-X, End-X und der Y-Reihe ein
void schalteWort(int startX, int endX, int y) {
  for (int x = startX; x <= endX; x++) {
    schalteBuchstabeEin(x, y);
  }
}

void setup() {
  Serial.begin(9600);
  matrix.begin();
  matrix.show(); // Alle LEDs initial aus
  
  if (!rtc.begin()) {
    while (1); // Stoppen, wenn keine RTC gefunden wurde
  }
  if (rtc.lostPower()) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  DateTime now = rtc.now();
  int stunde = now.hour();
  int minute = now.minute();

  aktualisiereWortuhr(stunde, minute);
  
  delay(1000); // Alle 10 Sekunden prüfen
}

void aktualisiereWortuhr(int h, int m) {
  matrix.clear(); // Zuerst alle LEDs ausschalten

  // IMMER AN: "ES IST" (Beispieldaten: Reihe 0, Plätze 0-1 und 3-5)
  schalteWort(0, 1, 0); // ES
  schalteWort(3, 5, 0); // IST

  int gerundeteMinute = (m / 5) * 5; 
  bool stundeErhoehen = false;

  // MINUTEN
    switch (gerundeteMinute) {
    case 5:   schalteWort(0, 3, 2);   schalteWort(12, 15, 2); break; // FÜNF NACH
    case 10:  schalteWort(12, 15, 1); schalteWort(12, 15, 2); break; // ZEHN NACH
    case 15:  schalteWort(4, 10, 2);  schalteWort(12, 15, 2); break; // VIERTEL NACH
    case 20:  schalteWort(0, 6, 1);   schalteWort(12, 15, 2); break; // ZWANZIG NACH
    case 25:  schalteWort(0, 3, 2);   schalteWort(0, 2, 3);   schalteWort(4, 7, 3);  stundeErhoehen = true; break; // FÜNF VOR HALB
    case 30:  schalteWort(4, 7, 3);   stundeErhoehen = true;  break; // 

More projects by frank-oenings