// This example toggles the debug LED (pin 13) on or off
// when a button on pin 2 is pressed.

// Include the Bounce2 library found here :
// https://github.com/thomasfredericks/Bounce2
#include <Bounce2.h>

#define BUTTON_PIN 2
int x=0;
int r=0;
int n=0;
int a=0;
int MyByte[8];
int Mark=0;
Bounce debouncer = Bounce(); // Instantiate a Bounce object

void setup() {
  pinMode(8,INPUT_PULLUP);
  debouncer.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
  debouncer.interval(25); // Use a debounce interval of 25 milliseconds
}

void addBit() {
  MyByte[Mark]=digitalRead(8);
  Mark=Mark+1;
  if (Mark == 8) {
    Keyboard.write(bin_dec());
    Mark = 0;
  }
}
int bin_dec() {
  r=0;
  while(x != 8){
    a=MyByte[x];
    if (x == 0) {
      n=1;
    } else if (x == 1) {
      n=2;
    } else if (x == 2) {
      n=4;
    } else if (x==3) {
      n=8;
    } else if (x==4) {
      n=16;
    } else if (x==5) {
      n=32;
    } else if (x==6) {
      n=64;
    } else if (x==7) {
      n=128;
    }
    r=r+a*n;
    x=x+1;
    //Keyboard.print(a);
    //Keyboard.print(" ");
  }
  //Keyboard.print(": ");
  return r;
}

void loop() {

  debouncer.update(); // Update the Bounce instance

  if ( debouncer.fell() ) {  // Call code if button transitions from HIGH to LOW
    addBit();
  }
}

Generated by Phil Hagelberg using scpaste at Tue Aug 21 09:45:52 2018. PDT. (original)