Hi!
I am programming a 5x5 Button Matrix right now and I used 1n4148 diodes for every switch to prevent ghosting and masking.
Well this is the code :
void check_button() {
PORTH |= (1 << 5);
if ((PINH & (1 << 4)) != 0) { button_state[0][0]=1;} else { button_state[0][0]=0; }
if ((PINE & (1 << 5)) != 0) { button_state[0][1]=1;} else { button_state[0][1]=0; }
if ((PINE & (1 << 3)) != 0) { button_state[0][2]=1;} else { button_state[0][2]=0; }
if ((PINH & (1 << 3)) != 0) { button_state[0][3]=1;} else { button_state[0][3]=0; }
if ((PINE & (1 << 4)) != 0) { button_state[0][4]=1;} else { button_state[0][4]=0; }
PORTH &= ~(1 << 5);
// delay(10);
PORTB |= (1 << 4);
if ((PINH & (1 << 4)) != 0) { button_state[1][0]=1;} else { button_state[1][0]=0; }
if ((PINE & (1 << 5)) != 0) { button_state[1][1]=1;} else { button_state[1][1]=0; }
if ((PINE & (1 << 3)) != 0) { button_state[1][2]=1;} else { button_state[1][2]=0; }
if ((PINH & (1 << 3)) != 0) { button_state[1][3]=1;} else { button_state[1][3]=0; }
if ((PINE & (1 << 4)) != 0) { button_state[1][4]=1;} else { button_state[1][4]=0; }
PORTB &= ~(1 << 4);
// delay(10);
PORTB |= (1 << 5);
if ((PINH & (1 << 4)) != 0) { button_state[2][0]=1;} else { button_state[2][0]=0; }
if ((PINE & (1 << 5)) != 0) { button_state[2][1]=1;} else { button_state[2][1]=0; }
if ((PINE & (1 << 3)) != 0) { button_state[2][2]=1;} else { button_state[2][2]=0; }
if ((PINH & (1 << 3)) != 0) { button_state[2][3]=1;} else { button_state[2][3]=0; }
if ((PINE & (1 << 4)) != 0) { button_state[2][4]=1;} else { button_state[2][4]=0; }
PORTB &= ~(1 << 5);
// delay(10);
PORTB |= (1 << 6);
if ((PINH & (1 << 4)) != 0) { button_state[3][0]=1;} else { button_state[3][0]=0; }
if ((PINE & (1 << 5)) != 0) { button_state[3][1]=1;} else { button_state[3][1]=0; }
if ((PINE & (1 << 3)) != 0) { button_state[3][2]=1;} else { button_state[3][2]=0; }
if ((PINH & (1 << 3)) != 0) { button_state[3][3]=1;} else { button_state[3][3]=0; }
if ((PINE & (1 << 4)) != 0) { button_state[3][4]=1;} else { button_state[3][4]=0; }
PORTB &= ~(1 << 6);
//delay(10);
PORTH |= (1 << 6);
if ((PINH & (1 << 4)) != 0) { button_state[4][0]=1;} else { button_state[4][0]=0; }
if ((PINE & (1 << 5)) != 0) { button_state[4][1]=1;} else { button_state[4][1]=0; }
if ((PINE & (1 << 3)) != 0) { button_state[4][2]=1;} else { button_state[4][2]=0; }
if ((PINH & (1 << 3)) != 0) { button_state[4][3]=1;} else { button_state[4][3]=0; }
if ((PINE & (1 << 4)) != 0) { button_state[4][4]=1;} else { button_state[4][4]=0; }
PORTH &= ~(1 << 6);
//delay(10);
// Serial.println((PINE & (1 << 3)),BIN);
button_process();
}
void button_process() {
for (int i = 0; i < 5; i++) {
for (int x = 0; x < 5; x++) {
if (button_state[i][x]) {Serial.println(i);Serial.println(x);}
}
}
}
The problem is that it only works with the delay(10) which i entered for testing.
I believe the 1N4148 Diodes switching time (4ns) might be to long and i should try schottkies, am I right or is there another problem?
The other thing i want to ask you guys deals with the timer pins, because i have only few pins left I need to use some pins which are affected by timers.
Can I use a timer without affecting its pins? or in other words, is it possible to detach pins from the Timers?
I mean I dont need 3 pins for my timers...
regards,
FLo