const int In1 = 7; const int In2 = 6; const int In3 = 5; const int In4 = 4; const int In5 = 3; const int In6 = 2; const int In7 = A2; const int In8 = A3; const int Ot1 = A4; const int Ot2 = 9; const int Ot3 = 10; const int Ot4 = 11; const int Ot5 = 12; const int Ot6 = 13; const int Ot7 = A1; const int Ot8 = A0; const int Inputs[]={In1,In2,In3,In4,In5,In6,In7,In8}; const int Outputs[]={Ot1,Ot2,Ot3,Ot4,Ot5,Ot6,Ot7,Ot8}; const unsigned long debounceTime = 10; //milliseconds unsigned long switchPressTime[8][8]; //when switches last changed state byte currentSwitchState[8][8]; byte oldSwitchState[8][8]={0}; byte actualState[8][8]; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(In1,OUTPUT); pinMode(In2,OUTPUT); pinMode(In3,OUTPUT); pinMode(In4,OUTPUT); pinMode(In5,OUTPUT); pinMode(In6,OUTPUT); pinMode(In7,OUTPUT); pinMode(In8,OUTPUT); pinMode(Ot1,INPUT); pinMode(Ot2,INPUT); pinMode(Ot3,INPUT); pinMode(Ot4,INPUT); pinMode(Ot5,INPUT); pinMode(Ot6,INPUT); pinMode(Ot7,INPUT); pinMode(Ot8,INPUT); } void loop() { // put your main code here, to run repeatedly: for(int i = 0; i < 8; i++){ digitalWrite(Inputs[i],HIGH); for(int j = 0; j < 8; j++){ currentSwitchState[i][j]= digitalRead(Outputs[j]); if( currentSwitchState[i][j] != oldSwitchState[i][j] ) { if( millis() - switchPressTime[i][j] >= debounceTime){ switchPressTime[i][j] = millis(); oldSwitchState[i][j] = currentSwitchState[i][j]; } } } digitalWrite(Inputs[i],LOW); }; for(int i=0; i < 8; i++){ for(int j=0; j < 8; j++){ Serial.write(oldSwitchState[i][j]); } }; Serial.print("STOP");