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 wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "uLCD_4DGL.h" 00004 #include "wave_player.h" 00005 #include "SDFileSystem.h" 00006 00007 RawSerial blue(p28,p27); 00008 uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; 00009 DigitalOut led1(LED1); 00010 Thread thread; 00011 Thread threadA; 00012 Thread threadB; 00013 Thread threadC; 00014 //Thread threadD; 00015 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card 00016 AnalogOut DACout(p18); 00017 wave_player waver(&DACout); 00018 Mutex stdio_mutex; 00019 DigitalOut latch(p15); 00020 DigitalOut enable(p16); 00021 SPI spi(p11, p12, p13); 00022 volatile int flag = 0; 00023 char bnum = 0; 00024 00025 00026 void RGB_LED(int red, int green, int blue) { 00027 unsigned int low_color=0; 00028 unsigned int high_color=0; 00029 high_color=(blue<<4)|((red&0x3C0)>>6); 00030 low_color=(((red&0x3F)<<10)|(green)); 00031 spi.write(high_color); 00032 spi.write(low_color); 00033 latch=1; 00034 latch=0; 00035 } 00036 00037 void threadBT(){ 00038 while(1) { 00039 if (blue.getc()=='!') { 00040 if (blue.getc()=='B') { //button data 00041 bnum = blue.getc(); //button number 00042 if ((bnum=='4')){ //is a number button 1..4 00043 uLCD.cls(); //turn on/off that num LED 00044 uLCD.printf("HELLO BT!");} 00045 } 00046 } 00047 } 00048 } 00049 00050 void thread1(){ 00051 while(true) { 00052 00053 stdio_mutex.lock(); 00054 uLCD.cls(); 00055 uLCD.printf("Pink Panther"); 00056 uLCD.text_width(2); 00057 uLCD.text_height(4); 00058 uLCD.color(RED); 00059 Thread::wait(1000); 00060 uLCD.cls(); 00061 stdio_mutex.unlock(); 00062 00063 } 00064 } 00065 00066 void thread2(){ 00067 FILE *wave_file; 00068 printf("\n\n\nHello, wave world!\n"); 00069 wave_file=fopen("/sd/mydir/sdtest.wav","r"); 00070 waver.play(wave_file); 00071 fclose(wave_file); 00072 } 00073 00074 void thread3(){ 00075 00076 int red=0; 00077 int green=0; 00078 int blue=0; 00079 spi.format(16,0); 00080 spi.frequency(500000); 00081 enable=0; 00082 latch=0; 00083 wait(2); 00084 for (red = 0; red<50; red = red+10) { 00085 for (blue = 0; blue<50; blue = blue+10) { 00086 for (green = 0; green<50; green = green+10) 00087 00088 { 00089 RGB_LED( red, green, blue); 00090 wait(.25); 00091 } 00092 } 00093 } 00094 00095 } 00096 00097 00098 int main() 00099 { 00100 thread.start(thread1); 00101 threadA.start(thread2); 00102 threadB.start(thread3); 00103 threadC.start(threadBT); 00104 // threadD.start(threadBT2); 00105 set_time(1570189620); // Set RTC time to Fri, 4 Oct 2019 11:47:00 00106 00107 00108 while (true) { 00109 00110 stdio_mutex.lock(); 00111 00112 time_t seconds = time(NULL); 00113 00114 //uLCD.printf("Time as seconds since January 1, 1970 = %d\n", seconds); 00115 00116 uLCD.cls(); 00117 uLCD.printf("Time is : %s", ctime(&seconds)); 00118 uLCD.text_width(2); 00119 uLCD.text_height(4); 00120 uLCD.color(RED); 00121 00122 00123 char buffer[32]; 00124 strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); 00125 //uLCD.printf("Time as a custom formatted string = %s", buffer); 00126 00127 wait(5); 00128 uLCD.cls(); 00129 stdio_mutex.unlock(); 00130 00131 00132 00133 } 00134 } 00135 00136 00137 00138 00139 00140 00141 00142
Generated on Thu Jul 14 2022 08:58:28 by
1.7.2