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: TextLCD mbed wave_player SDFileSystem
main.cpp
00001 #include "mbed.h" 00002 #include <wave_player.h> 00003 00004 //////////////////////////////////////// 00005 //////// general setting //////// 00006 //////////////////////////////////////// 00007 //#define USE_TextLCD_20x4 00008 #define USE_FIXED_IP 00009 00010 //////////////////////////////////////// 00011 //////// For TextLCD //////// 00012 //////////////////////////////////////// 00013 #include "TextLCD.h" 00014 #ifdef USE_TextLCD_20x4 00015 //TextLCD lcd( p24, p26, p27, p28, p29, p30, TextLCD::LCD20x4 ); // rs, e, d0-d3 00016 #else 00017 TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 00018 #endif 00019 00020 //////////////////////////////////////// 00021 //////// For SD_card //////// 00022 //////////////////////////////////////// 00023 #include "SDFileSystem.h" 00024 //SDFileSystem sd(p5, p6, p7, p13, "sd"); // mosi, miso, sclk, cs, name 00025 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate) 00026 00027 AnalogOut DACout(p18); 00028 wave_player waver(&DACout); 00029 00030 00031 void test_TextLCD( void ); 00032 void test_file_write( char *title, char *path ); 00033 int position( void ); 00034 00035 int main() { 00036 FILE *fp; 00037 fp = fopen("/sd/test.wav","r"); 00038 if (fp == NULL) { 00039 lcd.locate( 0, 0 ); 00040 lcd.printf("File couldn't open\n"); 00041 } else { 00042 lcd.locate( 0, 0 ); 00043 lcd.printf("Open ok\n"); 00044 } 00045 while (1) { 00046 lcd.locate( 0, 1 ); 00047 lcd.printf("File Playing\n"); 00048 waver.play(fp); 00049 } 00050 fclose(fp); 00051 } 00052 00053 00054 void test_TextLCD( void ) { 00055 // TextLCD test 00056 00057 #ifdef USE_TextLCD_20x4 00058 lcd.locate( 0, 0 ); 00059 for ( int i = 0, c = '0'; i < 20; i++, c++ ) 00060 lcd.putc( c ); 00061 00062 for ( int i = 0, c = 'A'; i < 20; i++, c++ ) 00063 lcd.putc( c ); 00064 00065 for ( int i = 0, c = 'a'; i < 20; i++, c++ ) 00066 lcd.putc( c ); 00067 for ( int i = 0, c = '0' - 10; i < 20; i++, c++ ) 00068 lcd.putc( c ); 00069 exit( 0 ); 00070 wait( 300 ); 00071 lcd.cls(); 00072 #endif // USE_TextLCD_20x4 00073 00074 lcd.locate( 0, 0 ); 00075 lcd.printf( "TextLCD: OK?" ); 00076 lcd.locate( 0, 1 ); 00077 lcd.printf( "" ); 00078 00079 } 00080 00081 void test_file_write( char *title, char *path ) { 00082 // SD card test 00083 lcd.locate( 0, position() ); 00084 lcd.printf( "%s: ", title ); 00085 00086 FILE *fp = fopen( path, "w" ); 00087 if ( fp == NULL ) { 00088 lcd.printf( "error" ); 00089 error( "Could not open file for write\n" ); 00090 } 00091 fprintf( fp, "The mbed writing a file through the star board orange (%s)!", title ); 00092 fclose( fp ); 00093 00094 lcd.printf( "OK." ); 00095 } 00096 00097 int position( void ) { 00098 static int p = 0; 00099 00100 #ifdef USE_TextLCD_20x4 00101 return( ++p % 4 ); 00102 #else 00103 return( ++p % 2 ); 00104 #endif 00105 }
Generated on Wed Jul 20 2022 10:44:15 by
1.7.2