use additional counter with ticker for WDR
Dependencies: libmDot mbed-rtos mbed
Fork of CardRead_20170613 by
main.cpp@20:d19c1cec6d42, 2017-06-17 (annotated)
- Committer:
- Dengjj
- Date:
- Sat Jun 17 08:09:28 2017 +0000
- Revision:
- 20:d19c1cec6d42
- Parent:
- 19:a0e9128dec64
use additional counter with ticker for WDR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:09250cd371d2 | 1 | #include "mbed.h" |
mfiore | 0:09250cd371d2 | 2 | #include "mDot.h" |
mfiore | 4:36e214ebfa56 | 3 | #include "MTSLog.h" |
mfiore | 0:09250cd371d2 | 4 | #include <string> |
mfiore | 0:09250cd371d2 | 5 | #include <vector> |
mfiore | 4:36e214ebfa56 | 6 | #include <algorithm> |
wang1tao | 16:847c028f4130 | 7 | #include <math.h> |
Dengjj | 15:04b37f329c84 | 8 | |
wang1tao | 16:847c028f4130 | 9 | #define RETURN_OK 0 |
wang1tao | 16:847c028f4130 | 10 | #define RETURN_ERR -1 |
wang1tao | 16:847c028f4130 | 11 | //define baudrate |
wang1tao | 16:847c028f4130 | 12 | #define PC_BAUDRATE 115200 |
wang1tao | 16:847c028f4130 | 13 | #define CARD_MACHINE_BAUDRATE 19200 |
wang1tao | 9:cf45820af9b9 | 14 | |
wang1tao | 16:847c028f4130 | 15 | #define COMMAND_LENGTH 7 |
wang1tao | 16:847c028f4130 | 16 | #define RESPONSE_LENGTH 16 |
wang1tao | 16:847c028f4130 | 17 | #define RINGBUFFER_SIZE 100 |
wang1tao | 16:847c028f4130 | 18 | |
wang1tao | 16:847c028f4130 | 19 | #define READ_PERIOD 1 |
wang1tao | 16:847c028f4130 | 20 | #define SEND_PERIOD 5 |
wang1tao | 16:847c028f4130 | 21 | |
Dengjj | 20:d19c1cec6d42 | 22 | Serial pc (USBTX, USBRX); |
Dengjj | 20:d19c1cec6d42 | 23 | Ticker timer; |
Dengjj | 20:d19c1cec6d42 | 24 | DigitalOut led1(PA_2); |
Dengjj | 20:d19c1cec6d42 | 25 | DigitalOut led2(PA_3); |
Dengjj | 20:d19c1cec6d42 | 26 | |
Dengjj | 20:d19c1cec6d42 | 27 | int flip = 0; |
Dengjj | 20:d19c1cec6d42 | 28 | int abc = 0; |
wang1tao | 16:847c028f4130 | 29 | mDot* dot; |
wang1tao | 16:847c028f4130 | 30 | |
Dengjj | 20:d19c1cec6d42 | 31 | void attime() { |
Dengjj | 20:d19c1cec6d42 | 32 | flip = !flip; |
Dengjj | 20:d19c1cec6d42 | 33 | abc = abc +1; |
Dengjj | 20:d19c1cec6d42 | 34 | if (abc == 2){ |
Dengjj | 20:d19c1cec6d42 | 35 | abc = 0; |
Dengjj | 20:d19c1cec6d42 | 36 | dot-> resetCpu(); |
Dengjj | 20:d19c1cec6d42 | 37 | } |
Dengjj | 20:d19c1cec6d42 | 38 | } |
Dengjj | 20:d19c1cec6d42 | 39 | |
Dengjj | 20:d19c1cec6d42 | 40 | int main() { |
wang1tao | 16:847c028f4130 | 41 | pc.baud(PC_BAUDRATE); |
Dengjj | 20:d19c1cec6d42 | 42 | pc.printf("11111"); |
wang1tao | 16:847c028f4130 | 43 | |
Dengjj | 20:d19c1cec6d42 | 44 | timer.attach(&attime, 5); |
Dengjj | 20:d19c1cec6d42 | 45 | pc.printf("22222"); |
wang1tao | 16:847c028f4130 | 46 | while(1) { |
Dengjj | 20:d19c1cec6d42 | 47 | if(flip == 0) { |
Dengjj | 20:d19c1cec6d42 | 48 | led1 = !led1; |
Dengjj | 20:d19c1cec6d42 | 49 | } else { |
Dengjj | 20:d19c1cec6d42 | 50 | led2 = !led2; |
Dengjj | 20:d19c1cec6d42 | 51 | } |
Dengjj | 20:d19c1cec6d42 | 52 | pc.printf("33333"); |
Dengjj | 20:d19c1cec6d42 | 53 | wait(1); |
Dengjj | 20:d19c1cec6d42 | 54 | abc = 0; |
wang1tao | 16:847c028f4130 | 55 | } |
wang1tao | 16:847c028f4130 | 56 | } |