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 PinDetect mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "uLCD_4DGL.h" 00004 #include "Speaker.h" 00005 #include "PinDetect.h" 00006 00007 int * frequency = NULL; 00008 enum Color { red, green, blue }; 00009 Color myCol = red; 00010 00011 uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin 00012 PwmOut RGBLED_r(p23); 00013 PwmOut RGBLED_g(p24); 00014 PwmOut RGBLED_b(p25); 00015 Speaker mySpeaker(p21); //setup speaker thread; 00016 PinDetect up(p20); 00017 PinDetect left(p19); 00018 PinDetect down(p17); 00019 PinDetect right(p16); 00020 PinDetect center(p15); 00021 00022 Serial pc(USBTX, USBRX); 00023 void center_button(void); 00024 00025 // Thread 1 00026 // print counter into first line and wait for 1 s 00027 //void uLCD_thread(void const *args) 00028 //{ 00029 // while(true) { // thread loop 00030 // uLCD.locate(0,0); 00031 // uLCD.printf("Frequency: %d",*frequency); 00032 // uLCD.locate(3,0); 00033 // //uLCD.printf("Color: %d", (int)Color)); 00034 // Thread::wait(1000); 00035 // } 00036 //} 00037 00038 // Thread 2 00039 // print counter into third line and wait for 0.5s 00040 void sound_thread(void const *args) 00041 { 00042 while(true) { // thread loop 00043 Thread::signal_wait(0x2); 00044 mySpeaker.PlayNote(*frequency, .1, .8); 00045 } 00046 } 00047 00048 // Thread 3 00049 // RGB LED 00050 //void RGB_thread(void const *args) 00051 //{ 00052 // while(true) { // thread loop 00053 // Thread::signal_wait(0x3); // wait 0.5s 00054 // switch (myCol) { 00055 // case red : 00056 // RGBLED_r = .5; 00057 // RGBLED_g = 0; 00058 // RGBLED_b = 0; 00059 // break; 00060 // case green : 00061 // RGBLED_r = 0; 00062 // RGBLED_g = 0.5; 00063 // RGBLED_b = 0; 00064 // break; 00065 // case blue : 00066 // RGBLED_r = 0; 00067 // RGBLED_g = 0; 00068 // RGBLED_b = 0.5; 00069 // break; 00070 // } 00071 // } 00072 //} 00073 00074 00075 00076 // 00077 00078 00079 00080 //Thread t1(uLCD_thread); 00081 00082 //Thread t3(RGB_thread); 00083 00084 int main() { 00085 Thread t2(sound_thread); 00086 pc.printf("Initializing...\n"); 00087 00088 00089 *frequency = 440; 00090 00091 00092 00093 00094 // center.attach_asserted(¢er_button); 00095 // center.setSampleFrequency(); 00096 // up.attach_asserted(&up_button); 00097 // up.setSampleFrequency(); 00098 // left.attach_asserted(&left_button); 00099 // left.setSampleFrequency(); 00100 // down.attach_asserted(&down_button); 00101 // down.setSampleFrequency(); 00102 // right.attach_asserted(&right_button); 00103 // right.setSampleFrequency(); 00104 00105 00106 00107 while(true) { // thread loop 00108 pc.printf("is this even working?\n"); 00109 Thread::wait(1000); 00110 t2.signal_set(0x2); 00111 00112 } 00113 } 00114 00115 //void center_button(void) { 00116 // t2.signal_set(0x2); 00117 //} 00118 //void up_button(void) { 00119 // *frequency += 50; 00120 //} 00121 //void down_button(void) { 00122 // *frequency -= 50; 00123 //} 00124 //void left_button(void) { 00125 // switch (myCol) { 00126 // case red : 00127 // myCol = blue; 00128 // break; 00129 // case green : 00130 // myCol = red; 00131 // break; 00132 // case blue : 00133 // myCol = green; 00134 // break; 00135 // } 00136 // t3.signal_set(0x3); 00137 //} 00138 //void right_button(void) { 00139 // switch (myCol) { 00140 // case red : 00141 // myCol = green; 00142 // break; 00143 // case green : 00144 // myCol = blue; 00145 // break; 00146 // case blue : 00147 // myCol = red; 00148 // break; 00149 // } 00150 // t3.signal_set(0x3); 00151 //} 00152 00153 00154
Generated on Sun Jul 31 2022 20:28:20 by
1.7.2