Programming 74hc165

Good evening,

I would like to build a keyboard using an Arduino Leonardo and 74HC165 shift registers.

I have already created a matrix keyboard with a case that includes multiple keys, and now I want to modify the code in order to use the 74HC165 instead.

Do you have a question? If so, you should post your code (in a code block) and a circuit drawing (paper and pen is good enough to start)... and ask any question.

Here is a very good introduction to shift registers, with text, video, drawings and code, from DroneBotWorkshop.com...

... oh... you have been trying...

I have already programmed the Leonardo with a matrix keyboard, and I need help on how I can modify the code to make the keyboard using 74HC165?

For example the part of the code now is

#include <Keypad.h>
#include <Keyboard.h>


         


const byte ROWS = 6; //four rows
const byte COLS = 6; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','4','5','6'},
  {'7','8','9','10','11','12'},
  {'13','14','15','16','17','18'},
  {'19','20','21','22','23','24'},
  {'25','26','27','28','29','30'},
  {'31','32','33','34','35','36'}
  
};
byte rowPins[ROWS] = {7, 6, 5, 4, 3, 2,}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11, 10, 9, 8,}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  Keyboard.begin();
  
}
 
void loop()
{
    char key = keypad.getKey();
    switch (key)
    {
        case '1':   ///MASTER_OFF
            Keyboard.press(KEY_LEFT_CTRL);
            Keyboard.press(KEY_LEFT_ALT);
            Keyboard.press(KEY_F9);
            delay(100);             
           Keyboard.releaseAll();
            break;
        case '2':   ///MASTER STRY
            Keyboard.press(KEY_LEFT_CTRL);
            Keyboard.press(KEY_LEFT_SHIFT);
            Keyboard.press(KEY_LEFT_ALT);
            Keyboard.press(KEY_F9);
            delay(100);             
           Keyboard.releaseAll();
            break;
        case '3':    ///MASTER LOW
            Keyboard.press(KEY_LEFT_CTRL);
            Keyboard.press(KEY_LEFT_SHIFT);
            Keyboard.press(KEY_F10);
            delay(100);
           Keyboard.releaseAll();
            break;

You should always post your complete code (sketch).

There’s a UNO/74HC165 example at the WOKWI site.

No way.

In the code you provided, all keyboard actions are hidden from the user in the Keyboard.h library. Therefore, there are no parts that could be modified to support work using 74HC165.

If you want to write your own library for the keyboard, start by studying the source code of the Keyboard.h

good evening

I made the following circuit with the 74HC165.

and the following code can someone tell me why it only worked for a while and then stopped.


const int numChips = 1;
const int numButtons = numChips * 8; // 48 bits συνολικά (θα χρησιμοποιήσουμε τα 36)

const int plPin = 8; // Parallel Load (active low)
const int clockPin = 9; // Clock
const int dataPin = 10; // Data Out

bool lastState[numButtons] = {0};

void setup() {
  pinMode(plPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, INPUT);
  digitalWrite(plPin, HIGH);
  digitalWrite(clockPin, LOW);

  Keyboard.begin();
  Serial.begin(9600);
}

void loop() {
  // Φόρτωσε τα δεδομένα από τα πλήκτρα
  digitalWrite(plPin, LOW);
  delayMicroseconds(5);
  digitalWrite(plPin, HIGH);

  // Διάβασε όλα τα bits
  for (int i = 0; i < numButtons; i++) {
    bool current = digitalRead(dataPin);
    if (current != lastState[i]) {
      lastState[i] = current;

      if (current == LOW) { // πατημένο πλήκτρο
        handleKeyPress(i);
      }
    }

    // Ρολάρισμα στο επόμενο bit
    digitalWrite(clockPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(clockPin, LOW);
  }

  delay(10); // μικρό debounce
}

void handleKeyPress(int index) {
  Serial.print("Key ");
  Serial.print(index + 1);
  Serial.println(" pressed");

  switch (index) {
    case 0: // MASTER_OFF
      Keyboard.press(KEY_LEFT_CTRL);
      Keyboard.press(KEY_LEFT_ALT);
      Keyboard.press(KEY_F9);
      delay(100);
      Keyboard.releaseAll();
      break;

    case 1: // MASTER STRY
      Keyboard.press(KEY_LEFT_CTRL);
      Keyboard.press(KEY_LEFT_SHIFT);
      Keyboard.press(KEY_LEFT_ALT);
      Keyboard.press(KEY_F9);
      delay(100);
      Keyboard.releaseAll();
      break;

    case 2: // MASTER LOW
      Keyboard.press(KEY_LEFT_CTRL);
      Keyboard.press(KEY_LEFT_SHIFT);
      Keyboard.press(KEY_F10);
      delay(100);
      Keyboard.releaseAll();
      break;
    case 3:   ///MASTER NORM
             Keyboard.press(KEY_LEFT_ALT);
             Keyboard.press(KEY_LEFT_SHIFT);
             Keyboard.press(KEY_F10);
            delay(100);
           Keyboard.releaseAll();
            break;
    case 4:   ///MASTER EMER
             Keyboard.press(KEY_LEFT_CTRL);
             Keyboard.press(KEY_LEFT_ALT);
             Keyboard.press(KEY_F10);
            delay(100);
           Keyboard.releaseAll();
            break;
    case 5:   ///M4 CODE ZERO
            Keyboard.press(KEY_LEFT_CTRL);
            Keyboard.press(KEY_LEFT_SHIFT);
            Keyboard.press(KEY_LEFT_ALT);
            Keyboard.press(KEY_F10);
            delay(100);
           Keyboard.releaseAll();
            break;
    case 6:   /// M4 CODE HOLD
            Keyboard.press(KEY_LEFT_ALT);
            Keyboard.press(KEY_LEFT_SHIFT);
            Keyboard.press(KEY_F11);
            delay(100);
           Keyboard.releaseAll();
            break;
    case 7:   ///CNI BACK UP
            Keyboard.press(KEY_LEFT_CTRL);
            Keyboard.press(KEY_LEFT_ALT);
            Keyboard.press(KEY_F11);
            delay(100);
           Keyboard.releaseAll();
            break;
    case 8:   ///CNI UFC
            Keyboard.press(KEY_LEFT_CTRL);
            Keyboard.press(KEY_LEFT_SHIFT);
            Keyboard.press(KEY_LEFT_ALT);
            Keyboard.press(KEY_F11);
            delay(100);
           Keyboard.releaseAll();
            break;
}
}
πληκτρολογήστε ή επικολλήστε τον κώδικα εδώ

This code even not compile, the Keyboard. object is not defined.

Please reread post #6.
The original code based on Keyboard library. Without editing the library you won't be able to integrate the 74HC165 in it.

I did not look at your code but I think you should move Arduino pin 9 from 165 pin 7 (/Q) to 165 pin 9 (Q). I believe that is your data line.

Here is a working example on how to use the 'HC165:

and some explanations:

And if you want to speed things up some, use the hardware SPI from your Arduino

  • You have not wired things properly.
    Check the data sheet to see how the pins should be connected.

  • We need to see an all encompassing schematic and good images of your actual wiring.

  • Digitlal ICs need power supply de-coupling.