Matthew Dorshimer
/
Lab3
yup
Fork of HelloWorld by
main.cpp@2:022b41ff9719, 2016-11-04 (annotated)
- Committer:
- Dorsh
- Date:
- Fri Nov 04 17:49:59 2016 +0000
- Revision:
- 2:022b41ff9719
- Parent:
- 0:fb6bbc10ffa0
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:fb6bbc10ffa0 | 1 | #include "mbed.h" |
simon | 0:fb6bbc10ffa0 | 2 | |
simon | 0:fb6bbc10ffa0 | 3 | DigitalOut myled(LED1); |
simon | 0:fb6bbc10ffa0 | 4 | |
Dorsh | 2:022b41ff9719 | 5 | #include "Keypad.h" |
Dorsh | 2:022b41ff9719 | 6 | #include "CAN.h" |
Dorsh | 2:022b41ff9719 | 7 | |
Dorsh | 2:022b41ff9719 | 8 | CAN can1(p30,p29); |
Dorsh | 2:022b41ff9719 | 9 | |
Dorsh | 2:022b41ff9719 | 10 | |
Dorsh | 2:022b41ff9719 | 11 | // Define your own keypad values |
Dorsh | 2:022b41ff9719 | 12 | char Keytable[] = { '1', '2', '3', // r0 |
Dorsh | 2:022b41ff9719 | 13 | '4', '5', '6', // r1 |
Dorsh | 2:022b41ff9719 | 14 | '7', '8', '9', // r2 |
Dorsh | 2:022b41ff9719 | 15 | '*', '0', '#', // r3 |
Dorsh | 2:022b41ff9719 | 16 | }; |
Dorsh | 2:022b41ff9719 | 17 | // c0 c1 c2 |
Dorsh | 2:022b41ff9719 | 18 | |
Dorsh | 2:022b41ff9719 | 19 | uint32_t Index; |
Dorsh | 2:022b41ff9719 | 20 | |
Dorsh | 2:022b41ff9719 | 21 | uint32_t cbAfterInput(uint32_t index) { |
Dorsh | 2:022b41ff9719 | 22 | Index = index; |
Dorsh | 2:022b41ff9719 | 23 | return 0; |
Dorsh | 2:022b41ff9719 | 24 | } |
Dorsh | 2:022b41ff9719 | 25 | |
Dorsh | 2:022b41ff9719 | 26 | void send(char *str) { |
Dorsh | 2:022b41ff9719 | 27 | printf("send(%s)\n",str); |
Dorsh | 2:022b41ff9719 | 28 | if(can1.write(CANMessage(1, str, 1))) { |
Dorsh | 2:022b41ff9719 | 29 | printf("wloop()\n"); |
Dorsh | 2:022b41ff9719 | 30 | printf("Message sent: \n"); |
Dorsh | 2:022b41ff9719 | 31 | } |
simon | 0:fb6bbc10ffa0 | 32 | } |
Dorsh | 2:022b41ff9719 | 33 | |
Dorsh | 2:022b41ff9719 | 34 | |
Dorsh | 2:022b41ff9719 | 35 | int main() { |
Dorsh | 2:022b41ff9719 | 36 | // r0 r1 r2 r3 c0 c1 c2 c3 |
Dorsh | 2:022b41ff9719 | 37 | Keypad keypad(p21, p22, p23, p24, p25, p26, p27); |
Dorsh | 2:022b41ff9719 | 38 | keypad.attach(&cbAfterInput); |
Dorsh | 2:022b41ff9719 | 39 | keypad.start(); // energize the keypad via c0-c3 |
Dorsh | 2:022b41ff9719 | 40 | |
Dorsh | 2:022b41ff9719 | 41 | while (1) { |
Dorsh | 2:022b41ff9719 | 42 | __wfi(); |
Dorsh | 2:022b41ff9719 | 43 | printf("Interrupted\r\n"); |
Dorsh | 2:022b41ff9719 | 44 | wait(0.5); |
Dorsh | 2:022b41ff9719 | 45 | char *msg = 0; |
Dorsh | 2:022b41ff9719 | 46 | *msg = Keytable[Index]; |
Dorsh | 2:022b41ff9719 | 47 | send(msg); |
Dorsh | 2:022b41ff9719 | 48 | printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); |
Dorsh | 2:022b41ff9719 | 49 | } |
Dorsh | 2:022b41ff9719 | 50 | } |