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
Fork of ECE4180_Lab3_Threads_Updated by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "uLCD_4DGL.h" 00004 #include "SDFileSystem.h" 00005 #include "wave_player.h" 00006 00007 /* shiftbright instantiation*/ 00008 PwmOut red(p21); 00009 PwmOut blue(p23); 00010 PwmOut green(p22); 00011 00012 /*uLCD instantiation*/ 00013 uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; 00014 Mutex mutex; 00015 00016 /* wave player instantiation*/ 00017 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card 00018 AnalogOut DACout(p18); 00019 wave_player waver(&DACout); 00020 00021 DigitalOut led1(LED1); 00022 DigitalOut led2(LED2); 00023 DigitalOut led4(LED4); 00024 00025 /* makes different colored squares the same color as the shiftbright*/ 00026 void lcd_thread1(void const *args) { 00027 int dist = 40; 00028 while (true) { 00029 if (red != 0) { 00030 mutex.lock(); 00031 //uLCD.cls(); 00032 //uLCD.filled_rectangle(64-25, 64-25, 64+25, 64+25, 0xff66cc); 00033 uLCD.cls(); 00034 uLCD.locate(64,64); 00035 uLCD.color(0xFFFF00); //yellow text 00036 uLCD.background_color(0xFFA500); //orange 00037 uLCD.filled_rectangle(64-dist, 64-dist, 64+dist, 64+dist, 0xff0000); //red square 00038 uLCD.text_mode(OPAQUE); 00039 uLCD.printf("Charmander!!"); 00040 mutex.unlock(); 00041 //Thread::wait(1000); 00042 } 00043 } 00044 } 00045 00046 /*makes different colored circle every time the bell sound sounds*/ 00047 void lcd_thread2(void const *args) { 00048 int rad = 40; 00049 while (true) { 00050 if (blue == 1) { 00051 mutex.lock(); 00052 uLCD.cls(); 00053 uLCD.locate(64,64); 00054 uLCD.color(0xFFFF00); //yellow text 00055 uLCD.background_color(0x0000ff); //blue background 00056 uLCD.filled_circle(64, 64, rad, 0xB7D5E9); //light blue circle 00057 uLCD.text_mode(OPAQUE); 00058 uLCD.printf("Bulbasaur!!"); 00059 //uLCD.filled_rectangle(64-25, 64-25, 64+25, 64+25, 0x336600); 00060 mutex.unlock(); 00061 } 00062 } 00063 } 00064 00065 /*play wav file on sd and when playing led1 turns on*/ 00066 void wav_thread3(void const *args) { 00067 while (1) { 00068 FILE *wave_file; 00069 wave_file=fopen("/sd/wavfiles/alarm.wav","r"); 00070 waver.play(wave_file); 00071 fclose(wave_file); 00072 } 00073 } 00074 00075 void light_thread4(void const *args) { 00076 while (true) { 00077 red = 0; 00078 blue = 1; 00079 green = 0; 00080 00081 Thread::wait(1000); 00082 00083 red = 0.8; 00084 blue = 0; 00085 green = 0; 00086 00087 Thread::wait(1000); 00088 } 00089 } 00090 00091 int main() { 00092 Thread thread1(lcd_thread1); 00093 Thread thread2(lcd_thread2); 00094 Thread thread3(wav_thread3); 00095 Thread thread4(light_thread4); 00096 while(1); 00097 }
Generated on Fri Jul 15 2022 23:47:41 by
1.7.2
