@@ -153,8 +153,9 @@ void keypad_keymatrix_scan(keypad_keymatrix_obj_t *self) {
153
153
for (size_t row = 0 ; row < common_hal_keypad_keymatrix_get_row_count (self ); row ++ ) {
154
154
// Switch this row to an output and set level appropriately
155
155
// Set low if columns_to_anodes is true, else set high.
156
+ digitalio_digitalinout_obj_t * row_dio = self -> row_digitalinouts -> items [row ];
156
157
common_hal_digitalio_digitalinout_switch_to_output (
157
- self -> row_digitalinouts -> items [ row ] , !self -> columns_to_anodes , DRIVE_MODE_PUSH_PULL );
158
+ row_dio , !self -> columns_to_anodes , DRIVE_MODE_PUSH_PULL );
158
159
159
160
for (size_t column = 0 ; column < common_hal_keypad_keymatrix_get_column_count (self ); column ++ ) {
160
161
mp_uint_t key_number = row_column_to_key_number (self , row , column );
@@ -175,8 +176,12 @@ void keypad_keymatrix_scan(keypad_keymatrix_obj_t *self) {
175
176
}
176
177
}
177
178
179
+ // Done with this row. Set its pin to its resting pull value briefly to shorten the time it takes
180
+ // to switch values. Just switching to an input with a (relatively weak) pullup/pulldown
181
+ // causes a slight delay in the output changing, which can cause false readings.
182
+ common_hal_digitalio_digitalinout_set_value (row_dio , self -> columns_to_anodes );
178
183
// Switch the row back to an input, pulled appropriately
179
184
common_hal_digitalio_digitalinout_switch_to_input (
180
- self -> row_digitalinouts -> items [ row ] , self -> columns_to_anodes ? PULL_UP : PULL_DOWN );
185
+ row_dio , self -> columns_to_anodes ? PULL_UP : PULL_DOWN );
181
186
}
182
187
}
0 commit comments