Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:be0aa2900453
- Parent:
- 0:a05c97d07ea7
- Child:
- 2:bac691bab19c
diff -r a05c97d07ea7 -r be0aa2900453 main.cpp
--- a/main.cpp Wed Apr 12 13:26:04 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-#include "mbed.h"
-
-#if defined (TARGET_KL25Z)
-#define ROW0 PTC9
-#define ROW1 PTC8
-#define ROW2 PTA5
-#define ROW3 PTA4
-#define COL0 PTA12
-#define COL1 PTD4
-#define COL2 PTA1
-#define COL3 PTA2
-#endif
-
-#define NUM_COL 4
-#define NUM_ROW 4
-#define NUM_KEY (NUM_COL * NUM_ROW)
-
-int key[ NUM_KEY ] = {
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0
-} ;
-
-unsigned char key_char[NUM_KEY] = {
- '1', '4', '7', '*',
- '2', '5', '8', '0',
- '3', '6', '9', '#',
- 'A', 'B', 'C', 'D'
-} ;
-
-
-DigitalIn *col[NUM_COL] ;
-DigitalOut *row[NUM_ROW] ;
-
-void init_hardware(void)
-{
- col[3] = new DigitalIn(PTC11, PullUp) ;
- col[2] = new DigitalIn(PTC10, PullUp) ;
- col[1] = new DigitalIn(PTC6, PullUp) ;
- col[0] = new DigitalIn(PTC5, PullUp) ;
-
- row[3] = new DigitalOut(PTC4, 1) ;
- row[2] = new DigitalOut(PTC3, 1) ;
- row[1] = new DigitalOut(PTC0, 1) ;
- row[0] = new DigitalOut(PTC7, 1) ;
-}
-
-int scan_key(int key[])
-{
- int r, c ;
- int count = 0 ;
-
- for (r = 0 ; r < NUM_ROW ; r++ ) {
- row[r]->write(0) ;
- for (c = 0 ; c < NUM_COL ; c++ ) {
- if (col[c]->read() == 0) {
- key[r * NUM_COL + c] = 1 ;
- count++ ;
- } else {
- key[r * NUM_COL + c] = 0 ;
- }
- }
- row[r]->write(1) ;
- }
- return(count) ;
-}
-
-void print_key(int key[])
-{
- int i ;
- for (i = 0 ; i < NUM_KEY ; i++ ) {
- if (key[i]) {
- printf("%c", key_char[i]) ;
- }
- }
-}
-
-int main() {
- int count ;
-
- init_hardware() ;
-
- printf("\n=== Matrix Key Test %s ===\n", __DATE__) ;
-
- while(1) {
- count = scan_key(key) ;
- if (count) {
- print_key(key) ;
- fflush(stdout) ;
- wait(0.2) ;
- }
- wait(0.1) ;
- }
-}