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 QEI SDFileSystem
main.cpp@2:263046c359da, 2019-08-16 (annotated)
- Committer:
- malithjkd
- Date:
- Fri Aug 16 07:59:10 2019 +0000
- Revision:
- 2:263046c359da
- Parent:
- 0:bdbd3d6fc5d5
SDcard write encoder value
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
malithjkd | 2:263046c359da | 3 | #include "QEI.h" |
malithjkd | 2:263046c359da | 4 | |
malithjkd | 2:263046c359da | 5 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board p5 - mosi, p6-miso, p7 - sck, p8 - cs |
malithjkd | 2:263046c359da | 6 | Serial pc (USBTX,USBRX); |
malithjkd | 2:263046c359da | 7 | QEI wheel (p29, p30, NC, 2000, QEI::X4_ENCODING); //for encoder |
malithjkd | 2:263046c359da | 8 | |
malithjkd | 2:263046c359da | 9 | |
malithjkd | 2:263046c359da | 10 | void sd_card_read_test(void); |
malithjkd | 2:263046c359da | 11 | void file_write_int(int input); |
malithjkd | 2:263046c359da | 12 | |
malithjkd | 2:263046c359da | 13 | int i= 2; |
malithjkd | 2:263046c359da | 14 | |
malithjkd | 2:263046c359da | 15 | int main() |
malithjkd | 2:263046c359da | 16 | { |
malithjkd | 2:263046c359da | 17 | sd_card_read_test(); |
malithjkd | 2:263046c359da | 18 | while(1){ |
malithjkd | 2:263046c359da | 19 | //pc.printf("Pulses is: %i\r\n", wheel.getPulses()); |
malithjkd | 2:263046c359da | 20 | file_write_int(wheel.getPulses()); |
malithjkd | 2:263046c359da | 21 | } |
malithjkd | 2:263046c359da | 22 | |
malithjkd | 2:263046c359da | 23 | } |
malithjkd | 2:263046c359da | 24 | |
malithjkd | 2:263046c359da | 25 | void sd_card_read_test(void) |
malithjkd | 2:263046c359da | 26 | { |
malithjkd | 2:263046c359da | 27 | pc.printf("SD card test"); |
mbed_official | 0:bdbd3d6fc5d5 | 28 | mkdir("/sd/mydir", 0777); |
mbed_official | 0:bdbd3d6fc5d5 | 29 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
malithjkd | 2:263046c359da | 30 | if(fp == NULL) |
malithjkd | 2:263046c359da | 31 | { |
mbed_official | 0:bdbd3d6fc5d5 | 32 | error("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 33 | } |
malithjkd | 2:263046c359da | 34 | fprintf(fp, "Test QUI\r\n"); |
malithjkd | 2:263046c359da | 35 | fclose(fp); |
malithjkd | 2:263046c359da | 36 | pc.printf("[ok]\r\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 37 | } |
malithjkd | 2:263046c359da | 38 | |
malithjkd | 2:263046c359da | 39 | void file_write_int(int input) |
malithjkd | 2:263046c359da | 40 | { |
malithjkd | 2:263046c359da | 41 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "a"); |
malithjkd | 2:263046c359da | 42 | if(fp == NULL) |
malithjkd | 2:263046c359da | 43 | { |
malithjkd | 2:263046c359da | 44 | error("Could not open file for write\n"); |
malithjkd | 2:263046c359da | 45 | } |
malithjkd | 2:263046c359da | 46 | fprintf(fp,"%d\r\n",input); |
malithjkd | 2:263046c359da | 47 | fclose(fp); |
malithjkd | 2:263046c359da | 48 | } |
malithjkd | 2:263046c359da | 49 |