#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();
void setup() {
pinMode(8,INPUT_PULLUP);
debouncer.attach(BUTTON_PIN,INPUT_PULLUP); debouncer.interval(25); }
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;
}
return r;
}
void loop() {
debouncer.update();
if ( debouncer.fell() ) { addBit();
}
}