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_OldbutworkswithRTOS
main.cpp
00001 //Include required libraries (uLCD, mbed, rtos, etc.) 00002 #include "mbed.h" 00003 #include "rtos.h" 00004 //#include "uLCD_4DGL.h" 00005 //#include "wave_player.h" 00006 //#include "stdio.h" 00007 //#include "RGBLed.h" 00008 //#include "SDFileSystem.h" 00009 00010 //Initialize all objects 00011 //uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; 00012 //SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card 00013 //RawSerial blue(p13,p14); 00014 //RGBLed myRGB(p21, p22, p23); 00015 DigitalOut led1(LED1); 00016 DigitalOut led2(LED2); 00017 DigitalOut led3(LED3); 00018 DigitalOut led4(LED4); 00019 //AnalogOut DACout(p18); 00020 //wave_player waver(&DACout); 00021 00022 Mutex mut; 00023 00024 // Thread 1 00025 // Bounce a circle around the screen centered randomly every 100ms 00026 void thread1(void const *args) 00027 { 00028 int i; 00029 //int xLCD, yLCD; 00030 while(true) { // thread loop 00031 mut.lock(); 00032 ////uLCD.baudrate(3000000); 00033 ////uLCD.cls(); 00034 ////uLCD.color(RED); 00035 ////uLCD.background_color(BLACK); 00036 ////uLCD.set_font(FONT_7X8); 00037 //////uLCD.text_mode(TRANSPARENT); 00038 ////uLCD.text_bold(ON); 00039 ////uLCD.printf("Count1: %d", i); 00040 led1 = !led1; 00041 mut.unlock(); 00042 i++; 00043 00044 Thread::wait(1000); 00045 } 00046 } 00047 00048 // Thread 2 00049 // prints a counter to the center of the screen 00050 void thread2(void const *args) 00051 { 00052 int k; 00053 while(true) { // thread loop 00054 mut.lock(); 00055 ////uLCD.baudrate(3000000); 00056 ////uLCD.cls(); 00057 ////uLCD.color(BLUE); 00058 ////uLCD.background_color(BLACK); 00059 ////uLCD.set_font(FONT_7X8); 00060 //////uLCD.text_mode(TRANSPARENT); 00061 ////uLCD.text_bold(ON); 00062 ////uLCD.printf("Count2: %d", k); 00063 led2 = !led2; 00064 mut.unlock(); 00065 k++; 00066 00067 Thread::wait(500); 00068 } 00069 } 00070 00071 //Thread 3 00072 //Do a "fancy" lighting effect on the RGB LED #include "ultrasonic.h" 00073 void thread3(void const *args) 00074 { 00075 //mut.lock(); 00076 //FILE *wave_file; 00077 //printf("\r\n\nHello, wave world!\n\r"); 00078 //Thread::wait(1000); 00079 //wave_file=fopen("/sd/chirp.wav","r"); 00080 //if(wave_file==NULL) printf("file open error!\n\n\r"); 00081 //waver.play(wave_file); 00082 //fclose(wave_file); 00083 //mut.unlock(); 00084 while(true) { // thread loop 00085 led3 = !led3; 00086 Thread::wait(1000); 00087 } 00088 } 00089 00090 // Thread 4 00091 // Reads inputs from the bluetooth module 00092 //void thread4(void const *args) 00093 //{ 00094 // while(true) { // thread loop 00095 // mut.lock(); 00096 // myRGB.write(1.0,0.0,0.0); //red 00097 // wait(2.0); 00098 // myRGB.write(0.0,1.0,0.0); //green 00099 // wait(2.0); 00100 // myRGB.write(0.0,0.0,1.0); //blue 00101 // wait(2.0); 00102 // myRGB.write(1.0,0.2,0.0); //yellow = red + some green 00103 // wait(2.0); 00104 // //white with a slow fade to black dimming effect 00105 // for (float x=1.0; x>=0.0001; x=x*0.99) { 00106 // myRGB.write(x, x, x); 00107 // wait(0.005); 00108 // } 00109 // mut.unlock(); 00110 // //wait(2.0); 00111 // Thread::wait(1000); 00112 // } 00113 //} 00114 00115 int main() 00116 { 00117 Thread t1(thread1); 00118 Thread t2(thread2); 00119 Thread t3(thread3); 00120 //Thread t4(thread4); 00121 //wait(0.1); // wait for uLCD ready 00122 00123 while(true) { // main is the next thread 00124 led4 = !led4; 00125 Thread::wait(500); // wait 0.5s 00126 } 00127 }
Generated on Fri Jul 15 2022 04:49:16 by
1.7.2