This simple program will test the functionality of the m3pi\'s usb port by reading a file on a usb flash drive (called YourText.txt) and printing it to the m3pi\'s inbuilt LCD display.
main.cpp@0:36cb440cb857, 2011-07-08 (annotated)
- Committer:
- Nicholas
- Date:
- Fri Jul 08 08:46:48 2011 +0000
- Revision:
- 0:36cb440cb857
M3pi USB text file read and LCD printf of same text document to LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nicholas | 0:36cb440cb857 | 1 | #include "mbed.h" |
Nicholas | 0:36cb440cb857 | 2 | #include "m3pi.h" |
Nicholas | 0:36cb440cb857 | 3 | #include "MSCFileSystem.h" |
Nicholas | 0:36cb440cb857 | 4 | |
Nicholas | 0:36cb440cb857 | 5 | DigitalOut myled(LED1); |
Nicholas | 0:36cb440cb857 | 6 | m3pi m3pi; |
Nicholas | 0:36cb440cb857 | 7 | MSCFileSystem msc("usb"); |
Nicholas | 0:36cb440cb857 | 8 | |
Nicholas | 0:36cb440cb857 | 9 | //The m3pi can have a maximum of 8 charicters on a row of it's display, so logically that is all we need to accomedate |
Nicholas | 0:36cb440cb857 | 10 | char YourText[8]; |
Nicholas | 0:36cb440cb857 | 11 | |
Nicholas | 0:36cb440cb857 | 12 | int main() { |
Nicholas | 0:36cb440cb857 | 13 | //set the file you want to open to /usb/YourFile.txt and we want to read it, so fopen needs 'r' |
Nicholas | 0:36cb440cb857 | 14 | FILE *YourFile = fopen("/usb/YourFile.txt", "r"); |
Nicholas | 0:36cb440cb857 | 15 | if (YourFile == NULL) { |
Nicholas | 0:36cb440cb857 | 16 | //if your file isnt there, turn an led on and do nothing else |
Nicholas | 0:36cb440cb857 | 17 | myled = 1; |
Nicholas | 0:36cb440cb857 | 18 | while (1) {} |
Nicholas | 0:36cb440cb857 | 19 | } |
Nicholas | 0:36cb440cb857 | 20 | //scan untill you hit then end of the document and put everything in YourText as a string |
Nicholas | 0:36cb440cb857 | 21 | while (!feof(YourFile)) { |
Nicholas | 0:36cb440cb857 | 22 | fscanf (YourFile, "%s", YourText); |
Nicholas | 0:36cb440cb857 | 23 | } |
Nicholas | 0:36cb440cb857 | 24 | m3pi.cls(); |
Nicholas | 0:36cb440cb857 | 25 | //and print your message! |
Nicholas | 0:36cb440cb857 | 26 | m3pi.printf("%s", YourText); |
Nicholas | 0:36cb440cb857 | 27 | } |