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.
Fork of Keyboard_Interrupt by
main.cpp@2:1432d7c567f4, 2015-06-02 (annotated)
- Committer:
- TakamiMa
- Date:
- Tue Jun 02 08:51:43 2015 +0000
- Revision:
- 2:1432d7c567f4
- Parent:
- 1:5440b3d7f435
If you type "5", "6", "7", "Enter", you receive "567".; this "567" is int variable in Program.; so you can calculate using it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TakamiMa | 0:14317ed79bae | 1 | #include "mbed.h" |
TakamiMa | 2:1432d7c567f4 | 2 | #include <string.h> |
TakamiMa | 2:1432d7c567f4 | 3 | |
TakamiMa | 2:1432d7c567f4 | 4 | //If you type more than two numbers, then type Enter, you get connected number. |
TakamiMa | 0:14317ed79bae | 5 | |
TakamiMa | 0:14317ed79bae | 6 | Serial pc(SERIAL_TX, SERIAL_RX); |
TakamiMa | 0:14317ed79bae | 7 | |
TakamiMa | 2:1432d7c567f4 | 8 | char line[16]; |
TakamiMa | 2:1432d7c567f4 | 9 | |
TakamiMa | 2:1432d7c567f4 | 10 | int counter = 0; |
TakamiMa | 2:1432d7c567f4 | 11 | |
TakamiMa | 0:14317ed79bae | 12 | void my_Interrupt(){ |
TakamiMa | 0:14317ed79bae | 13 | char key; |
TakamiMa | 0:14317ed79bae | 14 | key = pc.getc(); |
TakamiMa | 2:1432d7c567f4 | 15 | int number = int(key-'0'); |
TakamiMa | 2:1432d7c567f4 | 16 | if( (number > 9 || number < 0) && key!='\r'){ |
TakamiMa | 2:1432d7c567f4 | 17 | pc.printf("you can type only number, you cannot use dot.\r\n"); |
TakamiMa | 2:1432d7c567f4 | 18 | goto skip; |
TakamiMa | 2:1432d7c567f4 | 19 | } |
TakamiMa | 2:1432d7c567f4 | 20 | if(key == '\r'){ |
TakamiMa | 2:1432d7c567f4 | 21 | pc.printf("Enter\r\n"); |
TakamiMa | 2:1432d7c567f4 | 22 | pc.printf("%d\r\n", atoi(line)); |
TakamiMa | 2:1432d7c567f4 | 23 | counter=0; |
TakamiMa | 2:1432d7c567f4 | 24 | goto skip; |
TakamiMa | 2:1432d7c567f4 | 25 | } |
TakamiMa | 2:1432d7c567f4 | 26 | line[counter] = key; |
TakamiMa | 2:1432d7c567f4 | 27 | counter++; |
TakamiMa | 0:14317ed79bae | 28 | pc.printf("Interrupted %c\r\n", key); |
TakamiMa | 2:1432d7c567f4 | 29 | skip: |
TakamiMa | 0:14317ed79bae | 30 | } |
TakamiMa | 0:14317ed79bae | 31 | |
TakamiMa | 0:14317ed79bae | 32 | int main() { |
TakamiMa | 2:1432d7c567f4 | 33 | memset(line, '\0', 16); |
TakamiMa | 0:14317ed79bae | 34 | pc.attach(my_Interrupt, Serial::RxIrq); |
TakamiMa | 0:14317ed79bae | 35 | while(1){} |
TakamiMa | 0:14317ed79bae | 36 | } |