Created
January 2, 2026 13:38
-
-
Save kkroesch/dc7604cc9e528e84432b2d5183d7b0bd to your computer and use it in GitHub Desktop.
Universal Input/Output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Adafruit_TLC5947.h" | |
| // --- KONFIGURATION TLC5947 (Ausgabe) --- | |
| #define CLOCK_PIN A1 | |
| #define DATA_PIN A0 | |
| #define LATCH_PIN A2 | |
| Adafruit_TLC5947 tlc = Adafruit_TLC5947(1, CLOCK_PIN, DATA_PIN, LATCH_PIN); | |
| // --- KONFIGURATION EINGABE --- | |
| const int NUM_BITS = 4; | |
| // Taster Inputs (Bit 0, 1, 2, 3) | |
| const int btnPins[] = {2, 4, 6, 8}; | |
| // Feedback LEDs in den Tasten (Bit 0, 1, 2, 3) | |
| const int ledPins[] = {3, 5, 7, 9}; | |
| // Strobe Taster (Enter) | |
| const int strobeIn = 10; | |
| const int strobeOut = 11; // Feedback-Signal (kurzer Impuls) | |
| const int piezoPin = 11; // Sound | |
| // Zustandsspeicher für die Eingabe | |
| bool bitState[] = { false, false, false, false }; | |
| void setup() { | |
| Serial.begin(115200); | |
| tlc.begin(); | |
| // TLC löschen beim Start | |
| for(int i=0; i<24; i++) tlc.setPWM(i, 0); | |
| tlc.write(); | |
| // Pins Setup | |
| for (int i = 0; i < NUM_BITS; i++) { | |
| pinMode(btnPins[i], INPUT_PULLUP); | |
| pinMode(ledPins[i], OUTPUT); | |
| digitalWrite(ledPins[i], LOW); | |
| } | |
| pinMode(strobeIn, INPUT_PULLUP); | |
| pinMode(strobeOut, OUTPUT); | |
| // --- POST Eingabeeinheit (Lauflicht + 2x Blinken) --- | |
| for (int i = 0; i < 4; i++) { | |
| digitalWrite(ledPins[i], HIGH); | |
| delay(1000); | |
| digitalWrite(ledPins[i], LOW); | |
| } | |
| for (int k = 0; k < 2; k++) { | |
| delay(200); | |
| for (int i = 0; i < 4; i++) digitalWrite(ledPins[i], HIGH); | |
| delay(200); | |
| for (int i = 0; i < 4; i++) digitalWrite(ledPins[i], LOW); | |
| } | |
| tlcOutputTest(); | |
| tone(piezoPin, 2000, 100); // Begrüßungs-Beep | |
| Serial.println("Konsole bereit. Bitmuster eingeben und Strobe druecken."); | |
| } | |
| void loop() { | |
| // 1. Bit-Tasten abfragen (Toggle Logik für die Vorwahl) | |
| for (int i = 0; i < NUM_BITS; i++) { | |
| if (digitalRead(btnPins[i]) == LOW) { | |
| delay(20); // Debounce | |
| if (digitalRead(btnPins[i]) == LOW) { | |
| // Toggle Zustand | |
| bitState[i] = !bitState[i]; | |
| // Gelbe LED in der Taste aktualisieren | |
| digitalWrite(ledPins[i], bitState[i] ? HIGH : LOW); | |
| clickSound(); | |
| // Warten bis losgelassen (damit es nicht flackert) | |
| while(digitalRead(btnPins[i]) == LOW); | |
| } | |
| } | |
| } | |
| // 2. Strobe Taste (Übernahme in TLC Register) | |
| if (digitalRead(strobeIn) == LOW) { | |
| delay(20); | |
| if (digitalRead(strobeIn) == LOW) { | |
| // Feedback Impuls an Strobe Out (D11) | |
| digitalWrite(strobeOut, HIGH); | |
| // --- A. Wert auf TLC schreiben --- | |
| // Wir löschen erst die alten 4 Bits auf dem TLC (optional, falls gewünscht) | |
| // for(int i=0; i<4; i++) tlc.setPWM(i, 0); | |
| Serial.print("Lade Wert in Register: "); | |
| for (int i = 0; i < NUM_BITS; i++) { | |
| if (bitState[i]) { | |
| tlc.setPWM(i, 4095); // Rote LED am TLC an | |
| Serial.print("1"); | |
| } else { | |
| tlc.setPWM(i, 0); // Rote LED am TLC aus | |
| Serial.print("0"); | |
| } | |
| } | |
| Serial.println(); | |
| // WICHTIG: Befehl absenden! | |
| tlc.write(); | |
| // --- B. Eingabe zurücksetzen (Auto-Reset) --- | |
| // Wenn du willst, dass die Eingabe stehen bleibt, kommentiere diesen Block aus. | |
| for (int i = 0; i < NUM_BITS; i++) { | |
| bitState[i] = false; | |
| digitalWrite(ledPins[i], LOW); | |
| } | |
| // Warten bis Strobe losgelassen wird | |
| while(digitalRead(strobeIn) == LOW); | |
| digitalWrite(strobeOut, LOW); | |
| } | |
| } | |
| } | |
| // --- HILFSFUNKTION: TLC Output Test --- | |
| void tlcOutputTest() { | |
| // Einmal hin... | |
| for(int i = 0; i < 24; i++) { | |
| tlc.setPWM(i, 4095); // An | |
| if(i > 0) tlc.setPWM(i-1, 0); // Vorherige Aus | |
| tlc.write(); | |
| delay(30); | |
| } | |
| // ... und zurück | |
| for(int i = 23; i >= 0; i--) { | |
| tlc.setPWM(i, 4095); | |
| if(i < 23) tlc.setPWM(i+1, 0); | |
| tlc.write(); | |
| delay(30); | |
| } | |
| // Alles aus machen am Ende | |
| for(int i=0; i<24; i++) tlc.setPWM(i, 0); | |
| tlc.write(); | |
| } | |
| void clickSound() { | |
| tone(piezoPin, 4000, 5); // Kurzer "Klick" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment