serial transfer from desktop
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed
main.cpp@0:89af7d89f2d5, 2016-11-15 (annotated)
- Committer:
- ashea6
- Date:
- Tue Nov 15 21:42:29 2016 +0000
- Revision:
- 0:89af7d89f2d5
serial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashea6 | 0:89af7d89f2d5 | 1 | #include "mbed.h" |
ashea6 | 0:89af7d89f2d5 | 2 | #include "SDFileSystem.h" |
ashea6 | 0:89af7d89f2d5 | 3 | #include "uLCD_4DGL.h" |
ashea6 | 0:89af7d89f2d5 | 4 | |
ashea6 | 0:89af7d89f2d5 | 5 | DigitalOut myled(LED1); |
ashea6 | 0:89af7d89f2d5 | 6 | uLCD_4DGL uLCD(p28,p27,p29); |
ashea6 | 0:89af7d89f2d5 | 7 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
ashea6 | 0:89af7d89f2d5 | 8 | Serial blue(USBTX, USBRX); |
ashea6 | 0:89af7d89f2d5 | 9 | //Serial blue(p13, p14); // TX, RX |
ashea6 | 0:89af7d89f2d5 | 10 | |
ashea6 | 0:89af7d89f2d5 | 11 | |
ashea6 | 0:89af7d89f2d5 | 12 | int main() { |
ashea6 | 0:89af7d89f2d5 | 13 | blue.baud(9600); |
ashea6 | 0:89af7d89f2d5 | 14 | while(1) { |
ashea6 | 0:89af7d89f2d5 | 15 | //if (blue.readable()) |
ashea6 | 0:89af7d89f2d5 | 16 | //{ |
ashea6 | 0:89af7d89f2d5 | 17 | myled = 1; |
ashea6 | 0:89af7d89f2d5 | 18 | wait(0.2); |
ashea6 | 0:89af7d89f2d5 | 19 | myled = 0; |
ashea6 | 0:89af7d89f2d5 | 20 | wait(0.2); |
ashea6 | 0:89af7d89f2d5 | 21 | char buff[1000]; |
ashea6 | 0:89af7d89f2d5 | 22 | for (int j = 0; j < 20; j++) { |
ashea6 | 0:89af7d89f2d5 | 23 | buff[j] = 'z'; |
ashea6 | 0:89af7d89f2d5 | 24 | } |
ashea6 | 0:89af7d89f2d5 | 25 | int i = 0; |
ashea6 | 0:89af7d89f2d5 | 26 | bool flag = false; |
ashea6 | 0:89af7d89f2d5 | 27 | while(!flag) { |
ashea6 | 0:89af7d89f2d5 | 28 | buff[i] = blue.getc(); |
ashea6 | 0:89af7d89f2d5 | 29 | uLCD.printf("%c", buff[i]); |
ashea6 | 0:89af7d89f2d5 | 30 | //blue.putc(buff[i]); |
ashea6 | 0:89af7d89f2d5 | 31 | flag = buff[i] == '^'; |
ashea6 | 0:89af7d89f2d5 | 32 | if (flag) uLCD.printf("flag detected"); |
ashea6 | 0:89af7d89f2d5 | 33 | i++; |
ashea6 | 0:89af7d89f2d5 | 34 | } |
ashea6 | 0:89af7d89f2d5 | 35 | //uLCD.printf("%s", buff); |
ashea6 | 0:89af7d89f2d5 | 36 | |
ashea6 | 0:89af7d89f2d5 | 37 | mkdir("/sd/mydir", 0777); |
ashea6 | 0:89af7d89f2d5 | 38 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
ashea6 | 0:89af7d89f2d5 | 39 | if(fp == NULL) { |
ashea6 | 0:89af7d89f2d5 | 40 | error("Could not open file for write\n"); |
ashea6 | 0:89af7d89f2d5 | 41 | } |
ashea6 | 0:89af7d89f2d5 | 42 | fprintf(fp, buff); |
ashea6 | 0:89af7d89f2d5 | 43 | fclose(fp); |
ashea6 | 0:89af7d89f2d5 | 44 | //} |
ashea6 | 0:89af7d89f2d5 | 45 | } |
ashea6 | 0:89af7d89f2d5 | 46 | } |