/// Written by Kouzerumatsu (5 October 2022)

//. I need only two pins xD
#define PIN_CLK 5
#define PIN_DIN 4

char segfont[16] = {
  0b00000011, // 0
  0b10011111, // 1
  0b00100101, // 2
  0b00001101, // 3
  0b10011001, // 4
  0b01001001, // 5
  0b01000001, // 6
  0b00011111, // 7
  0b00000001, // 8
  0b00001001, // 9
  0b00000101, // A
  0b11000001, // b
  0b01100011, // C
  0b10000101, // d
  0b00100001, // e
  0b01110001, // F
};

void shiftBit(bool value){
  digitalWrite(PIN_CLK,LOW);
  digitalWrite(PIN_DIN,value);
  digitalWrite(PIN_CLK,HIGH);
}
void shiftByte(char value){
  shiftBit(value>>0&1);
  shiftBit(value>>1&1);
  shiftBit(value>>2&1);
  shiftBit(value>>3&1);
  shiftBit(value>>4&1);
  shiftBit(value>>5&1);
  shiftBit(value>>6&1);
  shiftBit(value>>7&1);
}

char segchar;

void setup() {
  pinMode(3,INPUT_PULLUP);
  pinMode(2,INPUT_PULLUP);
  pinMode(1,INPUT_PULLUP);
  pinMode(0,INPUT_PULLUP);
  pinMode(PIN_CLK,OUTPUT);
  pinMode(PIN_DIN,OUTPUT);
  segchar = 0b11111101;
}

void loop() {
  // Scan for keys
  uint16_t keypresses = 0;
  char keypress = -1;
  shiftByte(0b00001000);
  for (char k=0; k<4; k++){
    for (char l=0; l<4; l++){
      keypresses += keypresses | digitalRead(l);
      if(!digitalRead(l)){
        keypress = l*4 + k;
      }
    }
    shiftBit(0);
  }

  if(keypress > -1){
    segchar = segfont[keypress];
  }else{
    segchar &= ~1;
  }

  shiftByte(segchar);
  shiftByte(0);
  delay(200);
}
ATTINY8520PU
74HC595
74HC595
Kouzerumatsu, 5 October 2022