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: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
main.cpp
00001 #include "uLCD_4DGL.h" 00002 #include "mbed.h" 00003 #include "rtos.h" 00004 #include "SongPlayer.h" 00005 00006 uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; 00007 AnalogOut DACout(p18); 00008 DigitalOut myled(LED1); 00009 PwmOut RGBLED_r(p23); 00010 PwmOut RGBLED_g(p24); 00011 PwmOut RGBLED_b(p25); 00012 00013 float note[18]= {1568.0,1396.9,1244.5,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9, 00014 1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0 00015 }; 00016 float duration[18]= {0.48,0.24,0.72,0.48,0.24,0.48,0.24,0.24,0.24, 00017 0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48, 0.0 00018 }; 00019 00020 // mutex to make the lcd lib thread safe 00021 Mutex lcd_mutex; 00022 00023 // global variables 00024 int i = 0; 00025 int ix = 0; 00026 00027 void drawairplane(int x, int y) { 00028 uLCD.filled_rectangle(x, y+7, x+27, y+13, WHITE); 00029 uLCD.filled_rectangle(x, y, x+4, y+6, BLUE); 00030 uLCD.filled_rectangle(x, y+14, x+4, y+20, BLUE); 00031 uLCD.filled_rectangle(x+16, y-6, x+20, y+6, BLUE); 00032 uLCD.filled_rectangle(x+16, y+14, x+20, y+26, BLUE); 00033 uLCD.filled_rectangle(x+20, y+9, x+27, y+11, BLUE); 00034 uLCD.filled_rectangle(x+15, y+9, x+17, y+11, BLUE); 00035 uLCD.filled_rectangle(x+10, y+9, x+12, y+11, BLUE); 00036 uLCD.filled_rectangle(x+5, y+9, x+7, y+11, BLUE); 00037 } 00038 00039 // Thread 1 00040 // RGB LED 00041 void thread1(void const *args) 00042 { 00043 while(true) { // thread loop 00044 if (i < 10) { 00045 RGBLED_r = 0.0; 00046 RGBLED_g = (float) i / 10; 00047 RGBLED_b = 0.0; 00048 } else if (10 <= i && i < 20) { 00049 RGBLED_r = 0.0; 00050 RGBLED_g = (float) (20 - i) / 10; 00051 RGBLED_b = 0.0; 00052 } else if (20 <= i && i < 30) { 00053 RGBLED_r = (float) (i - 20) / 10; 00054 RGBLED_g = (float) (i - 20) / 10; 00055 RGBLED_b = (float) (i - 20) / 10; 00056 } else if (30 <= i && i < 40) { 00057 RGBLED_r = (float) (40 - i) / 10; 00058 RGBLED_g = (float) (40 - i) / 10; 00059 RGBLED_b = (float) (40 - i) / 10; 00060 } else { 00061 i = -1; 00062 } 00063 i++; 00064 Thread::wait(200); // wait 0.2s 00065 } 00066 } 00067 00068 00069 void thread2(void const *args) 00070 { 00071 while (true) { 00072 SongPlayer mySpeaker(p21); 00073 mySpeaker.PlaySong(note,duration); 00074 Thread::wait(6000); // wait 6s 00075 } 00076 } 00077 00078 00079 void thread3(void const *args) 00080 { 00081 while (true) { 00082 time_t seconds = time(NULL); 00083 lcd_mutex.lock(); 00084 uLCD.filled_rectangle(0, 0, 127, 63, BLACK); 00085 char buffer[32]; 00086 strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds)); 00087 uLCD.locate(0,0); 00088 uLCD.printf(buffer); 00089 lcd_mutex.unlock(); 00090 Thread::wait(1000); // wait 1s 00091 } 00092 } 00093 00094 void thread4(void const *args) 00095 { 00096 while (true) { 00097 lcd_mutex.lock(); 00098 uLCD.filled_rectangle(0, 63, 127, 127, BLACK); 00099 drawairplane(ix, 90); 00100 lcd_mutex.unlock(); 00101 ix += 1; 00102 if (ix > 100) { 00103 ix = 0; 00104 } 00105 Thread::wait(500); // wait 0.75s 00106 } 00107 } 00108 00109 00110 int main() { 00111 Thread t1(thread1); //start thread1 00112 Thread t2(thread2); //start thread2 00113 Thread t3(thread3); //start thread3 00114 Thread t4(thread4); //start thread3 00115 set_time(1256729737); 00116 while(1) { 00117 myled = 1; 00118 wait(0.2); 00119 myled = 0; 00120 wait(0.2); 00121 00122 } 00123 Thread::wait(200); // wait 0.2s 00124 }
Generated on Thu Oct 13 2022 18:35:30 by
1.7.2