Fork without short circuits
Fork of keypad by
No extra hardware is needed besides the wires and switches. The columns are outputs configured with open drain. The rows are inputs configured with pull up resistors. A key press pulls down its row. With scanning the column is determined thereafter.
See SaveKeypad for an example usage.
Diff: keypad.h
- Revision:
- 11:a45e64141ce6
- Parent:
- 10:9a9ec143840b
- Child:
- 13:fb6929fac0db
--- a/keypad.h Fri Nov 02 22:42:28 2012 +0000 +++ b/keypad.h Sat Nov 03 23:33:52 2012 +0000 @@ -85,6 +85,14 @@ */ void Stop(void); + /** Scan the keyboard for a debounced pressed key + */ + int DebouncedScan(void); + + /** Scan the keyboard for a pressed key + */ + int Scan(void); + /** User-defined function that to be called when a key is pressed * @param fptr A function pointer takes a uint32_t and * returns uint32_t @@ -92,21 +100,20 @@ void CallAfterInput(uint32_t (*fptr)(uint32_t)); protected: + static const int row_count = 4; + static const int col_count = 4; + InterruptIn _row0; InterruptIn _row1; InterruptIn _row2; InterruptIn _row3; + InterruptIn *_rows[row_count]; BusInOut _cols; // BusOut doesn't support mode() yet; need open drain to prevent short circuits... int _debounce; FPointer _input; // Called after each input - void _callback(int row, InterruptIn &therow); - void _cbRow0Fall(void); - void _cbRow1Fall(void); - void _cbRow2Fall(void); - void _cbRow3Fall(void); + void _callback(); void _setupFallTrigger(void); - void _dummy(void) { }; }; #endif // KEYPAD_H