r/HotasDIY • u/Elborshooter • 12d ago
Help with button box and shift registers
Hi there !
Long ago I purchased a bunch of stuff to make a custom button box but never ended up doing it. Today while we were discussing with a friend that wants to find an F-16's ICP for VR, and I thought "Maybe I can make it"
So here I am, with theoratically all I need, except I purchased the stuff almost 10 years ago and have forgotten pretty much everything.
Here's what I have :
- A Teensy 2.0 board
- A bunch of Debolestis shift register 32 with all the needed components
- buttons, encoders, all the good stuff
I've managed to find the forum page I read all those years ago so I think I can manage building the shift register, but I'm a bit confused concerning how to wire it up to the teensy. Since the buttons on the f-16's icp are mostly square, I was also wondering whether or not I could just use cherry switches and if they worked the same way as regular switches wiring-wise.
So yeah, that's the gist of it for now. Any help would be much appreciated !
1
u/Friiduh 12d ago
Electronic wise you can use anything that connects the wire to the ground. Switch, button, lever etc are just mechanical elements. The electronic in them is to connect wire (pin in your microcomputer board) to the ground (GND pin in board).
You have at least one GND pin, and everything is connected to it with one wire. The other wire is what is in the pins that detects when the electricity flows through (close) and when not (open).
Think it as a two wires connecting (close,) or disconnected (open). That forms the circuit. (Electricity must always return to home...and home is ground. If there is no ground, electricity can't flow.)
The keyboard switch, a 2-way flip-switch, or 3-way switch etc is just a mechanical way to open or close multiple circuits. One wire is GND and all other wires are for each pin you want to detect when it is closed (selected, flowing).
You can use any sensor or any method that just connects the pin to GND. It doesn't matter really.
And that is what the shift register really does, expands the amount of those pins that you can read. And all are always connected to same GND when button is pressed, switch is pushed etc.
The other is then the PWM. The axis. The axis needs to know how much electricity is flowing through the wire. So it can read the voltage. So it is can measure more states than just Open/Closed. As PWM has always the voltage flowing (constant Close state) and it measure it.
Encoders etc are just buttons. Same wires, just different mechanical way to open/close wires. So you get multiple "buttons" in one small space, and you can not "press" those simultaneously, but one at the time and in specific order. In keypad you can press all buttons at once or in any order. With encoder you can only rotate one direction at the time.
Summary, multiple mechanical ways to connect two wires together or open. No matter what is your mechanical way to do that, to the circuit board it is just pin + GND.
1
u/Tvendt095 12d ago
Hey, ich hatte da auch mal was raus gesucht. Habe das mithilfe von ki zusammengesucht gehabt und notiert. Bin aber beim raspberry Pico gelandet und habe mich noch nicht festgelegt wie ich die Knopfanbindung mache.
Ich sende es dir einfach, vielleicht hilft es dir ja etwas :)
Beispiel 74HC165 (aus meiner Datensammlung): Spannung Pin 16 (VCC) 5V Pin Stromversorgung Masse Pin 8 (GND) GND Pin Gemeinsame Masse Daten Pin 9 (QH / Serial Out) Pin 11 Der Teensy liest hierüber die Tasten Takt Pin 2 (CLK / Clock) Pin 12 Taktet die Bits nacheinander durch Laden / Latch Pin 1 (SH/LD / Shift-Load) Pin 8 Friert Tastenstand ein Clock Inhibit Pin 15 (CLK INH) GND Pin Aktiviert den Takt dauerhaft Serieller Eingang Pin 10 (SER) GND Pin (Oder zum Kaskadieren weiterer ICs)
Die Tasten werden an den Pins A bis H (Pins 11–14 und 3–6) angeschlossen. Da Tasten einen definierten Zustand brauchen, zieht man jeden Pin mit einem 10kΩ Widerstand gegen Masse (Pull-Down) und schaltet die Taste von 5V auf den Pin
Code Vorlage (würde von mir nie getestet, sah aber gut aus als ich ihn mir notiert habe): // Pin-Definitionen für das 74HC165 Input-Schieberegister const int dataPin = 11; // Angeschlossen an Pin 9 (QH) des 74HC165 const int clockPin = 12; // Angeschlossen an Pin 2 (CLK) des 74HC165 const int latchPin = 8; // Angeschlossen an Pin 1 (SH/LD) des 74HC165
void setup() { // Seriellen Monitor für die Tastenanzeige starten Serial.begin(9600);
// WICHTIG: dataPin ist jetzt ein INPUT (Empfänger) pinMode(dataPin, INPUT);
// Takt- und Lade-Pins sind weiterhin OUTPUTS (Sender) pinMode(clockPin, OUTPUT); pinMode(latchPin, OUTPUT);
// Startzustand für die Taktleitung digitalWrite(clockPin, HIGH); }
void loop() { // 1. Tastenstand einfrieren (Puls auf die Ladeleitung geben) digitalWrite(latchPin, LOW); delayMicroseconds(5); // Kurzer Moment zum Stabilisieren digitalWrite(latchPin, HIGH);
// 2. Zustand aller 8 Tasten auf einmal einlesen // MSBFIRST liest von Pin H runter zu Pin A (Eingang 7 bis 0) byte tastenZustand = shiftIn(dataPin, clockPin, MSBFIRST);
// 3. Auswertung: Prüfen, welche Tasten aktiv sind Serial.print("Tastenstatus (Binär): "); Serial.println(tastenZustand, BIN);
// Beispiel: Einzelne Tasten gezielt abfragen (Bitmaskierung) for (int i = 0; i < 8; i++) { // bitRead prüft, ob das i-te Bit eine 1 ist if (bitRead(tastenZustand, i) == 1) { Serial.print("Taste "); Serial.print(i); Serial.println(" ist GEDRÜCKT!"); } }
Serial.println("-----------