Test SD

Dependencies:   FatFileSystem SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // example writing to SD card, sford
00002 
00003 #include "mbed.h"
00004 #include "SDFileSystem.h"
00005 #include "TextLCD.h"
00006 
00007 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30);//NGX mX-Base-Board Ver1.2 Type
00008 //(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, int columns, int rows)
00009 
00010 DigitalOut led(LED1);
00011 
00012 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
00013                 // mosi, miso, sclk, cs
00014 
00015 int main() {
00016 
00017     lcd.cls();
00018     lcd.locate(0,0);
00019     lcd.printf("Hello SD!\n");   
00020 
00021     mkdir("/sd/Tomodir", 0777);
00022     
00023     FILE *fp = fopen("/sd/Tomodir/Tomo.txt", "w");
00024     if(fp == NULL) {
00025         error("Could not open file for write\n");
00026     }
00027     fprintf(fp, "heehaw!");
00028     fclose(fp); 
00029     
00030     lcd.locate(0,1);
00031     lcd.printf("Goodbye SD!\n");
00032     
00033     while(1) {
00034         led = 1;
00035         wait(0.2);
00036         led = 0;
00037         wait(0.2);
00038     }
00039 }