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.
Dependencies: mbed
main.cpp@0:786207d961f4, 2015-03-13 (annotated)
- Committer:
- dousape2
- Date:
- Fri Mar 13 03:33:26 2015 +0000
- Revision:
- 0:786207d961f4
- Child:
- 1:533ef4c5f7ab
logicka sonda
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dousape2 | 0:786207d961f4 | 1 | #include "mbed.h" |
| dousape2 | 0:786207d961f4 | 2 | |
| dousape2 | 0:786207d961f4 | 3 | PortIn myIOs(PortC, 0xFFFF); // PC_all |
| dousape2 | 0:786207d961f4 | 4 | |
| dousape2 | 0:786207d961f4 | 5 | Serial pc(SERIAL_TX, SERIAL_RX); |
| dousape2 | 0:786207d961f4 | 6 | |
| dousape2 | 0:786207d961f4 | 7 | Ticker toggle_ticker; |
| dousape2 | 0:786207d961f4 | 8 | |
| dousape2 | 0:786207d961f4 | 9 | DigitalOut led(LED1); |
| dousape2 | 0:786207d961f4 | 10 | |
| dousape2 | 0:786207d961f4 | 11 | int pin =0; |
| dousape2 | 0:786207d961f4 | 12 | int vypis =0; |
| dousape2 | 0:786207d961f4 | 13 | |
| dousape2 | 0:786207d961f4 | 14 | bool start = true; |
| dousape2 | 0:786207d961f4 | 15 | |
| dousape2 | 0:786207d961f4 | 16 | void toggle() |
| dousape2 | 0:786207d961f4 | 17 | { |
| dousape2 | 0:786207d961f4 | 18 | int meas,z; |
| dousape2 | 0:786207d961f4 | 19 | meas=myIOs.read(); |
| dousape2 | 0:786207d961f4 | 20 | |
| dousape2 | 0:786207d961f4 | 21 | led= !led; |
| dousape2 | 0:786207d961f4 | 22 | if (meas == pin ) { |
| dousape2 | 0:786207d961f4 | 23 | start = true; |
| dousape2 | 0:786207d961f4 | 24 | } |
| dousape2 | 0:786207d961f4 | 25 | if(start) { |
| dousape2 | 0:786207d961f4 | 26 | if(vypis==1) { |
| dousape2 | 0:786207d961f4 | 27 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 28 | for (z =32768; z > 0; z >>= 1) { |
| dousape2 | 0:786207d961f4 | 29 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 30 | printf(((meas & z) == z) ? "1" : "0"); |
| dousape2 | 0:786207d961f4 | 31 | } |
| dousape2 | 0:786207d961f4 | 32 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 33 | printf("\n"); |
| dousape2 | 0:786207d961f4 | 34 | } else if(vypis==2) { |
| dousape2 | 0:786207d961f4 | 35 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 36 | printf("%d\n", meas); |
| dousape2 | 0:786207d961f4 | 37 | } else if(vypis==3) { |
| dousape2 | 0:786207d961f4 | 38 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 39 | printf("%o\n", meas); |
| dousape2 | 0:786207d961f4 | 40 | } else if(vypis==4) { |
| dousape2 | 0:786207d961f4 | 41 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 42 | printf("%x\n", meas); |
| dousape2 | 0:786207d961f4 | 43 | } else { |
| dousape2 | 0:786207d961f4 | 44 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 45 | printf("DEC: %d, HEX: %x, OCT: %o, BIN: ", meas,meas,meas); |
| dousape2 | 0:786207d961f4 | 46 | for (z =32768; z > 0; z >>= 1) { |
| dousape2 | 0:786207d961f4 | 47 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 48 | printf(((meas & z) == z) ? "1" : "0"); |
| dousape2 | 0:786207d961f4 | 49 | } |
| dousape2 | 0:786207d961f4 | 50 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 51 | printf("\n"); |
| dousape2 | 0:786207d961f4 | 52 | } |
| dousape2 | 0:786207d961f4 | 53 | } |
| dousape2 | 0:786207d961f4 | 54 | } |
| dousape2 | 0:786207d961f4 | 55 | |
| dousape2 | 0:786207d961f4 | 56 | void flushSerialPort() |
| dousape2 | 0:786207d961f4 | 57 | { |
| dousape2 | 0:786207d961f4 | 58 | while(pc.readable()) |
| dousape2 | 0:786207d961f4 | 59 | pc.getc(); |
| dousape2 | 0:786207d961f4 | 60 | return; |
| dousape2 | 0:786207d961f4 | 61 | } |
| dousape2 | 0:786207d961f4 | 62 | |
| dousape2 | 0:786207d961f4 | 63 | |
| dousape2 | 0:786207d961f4 | 64 | int main() |
| dousape2 | 0:786207d961f4 | 65 | { |
| dousape2 | 0:786207d961f4 | 66 | myIOs.mode(PullNone); // PullDown PullUp PullNone OpenDrain |
| dousape2 | 0:786207d961f4 | 67 | |
| dousape2 | 0:786207d961f4 | 68 | |
| dousape2 | 0:786207d961f4 | 69 | |
| dousape2 | 0:786207d961f4 | 70 | int prijData=0; |
| dousape2 | 0:786207d961f4 | 71 | int Data1=0; |
| dousape2 | 0:786207d961f4 | 72 | float Data2=0; |
| dousape2 | 0:786207d961f4 | 73 | pc.baud(115200); |
| dousape2 | 0:786207d961f4 | 74 | toggle_ticker.detach(); |
| dousape2 | 0:786207d961f4 | 75 | toggle_ticker.attach(&toggle, 0.01); |
| dousape2 | 0:786207d961f4 | 76 | printf("\nLogic sond.\n"); |
| dousape2 | 0:786207d961f4 | 77 | |
| dousape2 | 0:786207d961f4 | 78 | while(1) { |
| dousape2 | 0:786207d961f4 | 79 | prijData=pc.scanf("%d %f",&Data1,&Data2); |
| dousape2 | 0:786207d961f4 | 80 | if(prijData==2) { |
| dousape2 | 0:786207d961f4 | 81 | //pc.printf() |
| dousape2 | 0:786207d961f4 | 82 | if(Data1==1) { |
| dousape2 | 0:786207d961f4 | 83 | toggle_ticker.detach(); |
| dousape2 | 0:786207d961f4 | 84 | toggle_ticker.attach(&toggle, Data2); |
| dousape2 | 0:786207d961f4 | 85 | } else if(Data1==2) { |
| dousape2 | 0:786207d961f4 | 86 | toggle_ticker.detach(); |
| dousape2 | 0:786207d961f4 | 87 | } else if(Data1==3) { |
| dousape2 | 0:786207d961f4 | 88 | pin=(int)Data2; |
| dousape2 | 0:786207d961f4 | 89 | start = false; |
| dousape2 | 0:786207d961f4 | 90 | } else if(Data1==4) { |
| dousape2 | 0:786207d961f4 | 91 | vypis=(int)Data2; |
| dousape2 | 0:786207d961f4 | 92 | } |
| dousape2 | 0:786207d961f4 | 93 | } else { |
| dousape2 | 0:786207d961f4 | 94 | toggle_ticker.detach(); |
| dousape2 | 0:786207d961f4 | 95 | |
| dousape2 | 0:786207d961f4 | 96 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 97 | printf("HELP - MENU\n"); |
| dousape2 | 0:786207d961f4 | 98 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 99 | printf("Data send to PC is in dec format.\n"); |
| dousape2 | 0:786207d961f4 | 100 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 101 | printf("Set data exactly.\n"); |
| dousape2 | 0:786207d961f4 | 102 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 103 | printf("Write to console: \"xx yy\", where xx is a code of seting and yy his value.\n"); |
| dousape2 | 0:786207d961f4 | 104 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 105 | printf("01 y.yyy - set period[s] to send data to PC and start reading value, example:01 0.01\n"); |
| dousape2 | 0:786207d961f4 | 106 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 107 | printf("02 0 - stop reading value, example:02 0\n"); |
| dousape2 | 0:786207d961f4 | 108 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 109 | printf("03 yyyy - Wait for pin to get to log.1. yyyy write in dec example:03 2000\n"); |
| dousape2 | 0:786207d961f4 | 110 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 111 | printf("04 yy - print yy: 00-default all, 01-bin, 02-dec, 03-oct, 04-hex, example:04 00\n"); |
| dousape2 | 0:786207d961f4 | 112 | while(!pc.writeable()); |
| dousape2 | 0:786207d961f4 | 113 | printf("end HELP\n"); |
| dousape2 | 0:786207d961f4 | 114 | flushSerialPort(); |
| dousape2 | 0:786207d961f4 | 115 | |
| dousape2 | 0:786207d961f4 | 116 | } |
| dousape2 | 0:786207d961f4 | 117 | // wait(0.2); // 200 ms |
| dousape2 | 0:786207d961f4 | 118 | } |
| dousape2 | 0:786207d961f4 | 119 | } |