init
Dependencies: SDFileSystem mbed-rtos mbed wave_player
main.cpp@1:4fd1a4e54648, 21 months ago (annotated)
- Committer:
- emanuel22e
- Date:
- Fri Oct 14 19:36:37 2022 +0000
- Revision:
- 1:4fd1a4e54648
- Parent:
- 0:47321458789d
init
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emanuel22e | 1:4fd1a4e54648 | 1 | //#include "mbed.h" |
| emanuel22e | 1:4fd1a4e54648 | 2 | //#include "rtos.h" |
| emanuel22e | 1:4fd1a4e54648 | 3 | //#include "wave_player.h" |
| emanuel22e | 1:4fd1a4e54648 | 4 | //#include "SDFileSystem.h" |
| emanuel22e | 1:4fd1a4e54648 | 5 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); |
| emanuel22e | 1:4fd1a4e54648 | 6 | //PwmOut red(p21); |
| emanuel22e | 1:4fd1a4e54648 | 7 | //PwmOut green(p22); |
| emanuel22e | 1:4fd1a4e54648 | 8 | //PwmOut blue(p23); |
| emanuel22e | 1:4fd1a4e54648 | 9 | //AnalogOut speaker(p18); |
| emanuel22e | 1:4fd1a4e54648 | 10 | //wave_player waver(&speaker); |
| emanuel22e | 1:4fd1a4e54648 | 11 | //Thread thread1; |
| emanuel22e | 1:4fd1a4e54648 | 12 | //Thread thread2; |
| emanuel22e | 1:4fd1a4e54648 | 13 | //void t1() { |
| emanuel22e | 1:4fd1a4e54648 | 14 | // red = 0; |
| emanuel22e | 1:4fd1a4e54648 | 15 | // green = 0; |
| emanuel22e | 1:4fd1a4e54648 | 16 | // blue = 0; |
| emanuel22e | 1:4fd1a4e54648 | 17 | // while (1) { |
| emanuel22e | 1:4fd1a4e54648 | 18 | // red = 1; |
| emanuel22e | 1:4fd1a4e54648 | 19 | // green = 0; |
| emanuel22e | 1:4fd1a4e54648 | 20 | // blue = 0; |
| emanuel22e | 1:4fd1a4e54648 | 21 | // Thread::wait(300); |
| emanuel22e | 1:4fd1a4e54648 | 22 | // red = 0; |
| emanuel22e | 1:4fd1a4e54648 | 23 | // green = 1; |
| emanuel22e | 1:4fd1a4e54648 | 24 | // blue = 0; |
| emanuel22e | 1:4fd1a4e54648 | 25 | // Thread::wait(300); |
| emanuel22e | 1:4fd1a4e54648 | 26 | // red = 0; |
| emanuel22e | 1:4fd1a4e54648 | 27 | // green = 0; |
| emanuel22e | 1:4fd1a4e54648 | 28 | // blue = 1; |
| emanuel22e | 1:4fd1a4e54648 | 29 | // Thread::wait(300); |
| emanuel22e | 1:4fd1a4e54648 | 30 | // |
| emanuel22e | 1:4fd1a4e54648 | 31 | // } |
| emanuel22e | 1:4fd1a4e54648 | 32 | //void t2() { |
| emanuel22e | 1:4fd1a4e54648 | 33 | // FILE *wave_file; |
| emanuel22e | 1:4fd1a4e54648 | 34 | // //open wav file and play it |
| emanuel22e | 1:4fd1a4e54648 | 35 | // wave_file=fopen("/sd/thread_sound.wav","r"); |
| emanuel22e | 1:4fd1a4e54648 | 36 | // waver.play(wave_file); |
| emanuel22e | 1:4fd1a4e54648 | 37 | // fclose(wave_file); |
| emanuel22e | 1:4fd1a4e54648 | 38 | // //end of program |
| emanuel22e | 1:4fd1a4e54648 | 39 | // Thread::wait(500); |
| emanuel22e | 1:4fd1a4e54648 | 40 | //} |
| emanuel22e | 1:4fd1a4e54648 | 41 | // |
| emanuel22e | 1:4fd1a4e54648 | 42 | //int main() { |
| emanuel22e | 1:4fd1a4e54648 | 43 | // thread1.start(t1); |
| emanuel22e | 1:4fd1a4e54648 | 44 | // thread2.start(t2); |
| emanuel22e | 1:4fd1a4e54648 | 45 | // while(1) { |
| emanuel22e | 1:4fd1a4e54648 | 46 | // |
| emanuel22e | 1:4fd1a4e54648 | 47 | // } |
| emanuel22e | 1:4fd1a4e54648 | 48 | //} |
| emanuel22e | 1:4fd1a4e54648 | 49 | |
| emanuel22e | 1:4fd1a4e54648 | 50 | |
| emanuel22e | 0:47321458789d | 51 | #include "mbed.h" |
| emanuel22e | 0:47321458789d | 52 | #include "rtos.h" |
| emanuel22e | 0:47321458789d | 53 | #include "wave_player.h" |
| emanuel22e | 0:47321458789d | 54 | #include "SDFileSystem.h" |
| emanuel22e | 1:4fd1a4e54648 | 55 | #include "uLCD_4DGL.h" |
| emanuel22e | 0:47321458789d | 56 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
| emanuel22e | 0:47321458789d | 57 | PwmOut red(p21); |
| emanuel22e | 0:47321458789d | 58 | PwmOut green(p22); |
| emanuel22e | 0:47321458789d | 59 | PwmOut blue(p23); |
| emanuel22e | 1:4fd1a4e54648 | 60 | PwmOut speaker(p26); |
| emanuel22e | 1:4fd1a4e54648 | 61 | Serial bluemod(p13,p14); |
| emanuel22e | 1:4fd1a4e54648 | 62 | //wave_player waver(&speaker); |
| emanuel22e | 1:4fd1a4e54648 | 63 | uLCD_4DGL uLCD(p28,p27,p11); |
| emanuel22e | 1:4fd1a4e54648 | 64 | //Thread thread1; |
| emanuel22e | 0:47321458789d | 65 | Thread thread2; |
| emanuel22e | 1:4fd1a4e54648 | 66 | Thread thread3; |
| emanuel22e | 1:4fd1a4e54648 | 67 | Thread thread4; |
| emanuel22e | 1:4fd1a4e54648 | 68 | Mutex u_mutex; |
| emanuel22e | 0:47321458789d | 69 | void t1() { |
| emanuel22e | 0:47321458789d | 70 | red = 0; |
| emanuel22e | 0:47321458789d | 71 | green = 0; |
| emanuel22e | 0:47321458789d | 72 | blue = 0; |
| emanuel22e | 0:47321458789d | 73 | while (1) { |
| emanuel22e | 0:47321458789d | 74 | red = 1; |
| emanuel22e | 0:47321458789d | 75 | green = 0; |
| emanuel22e | 0:47321458789d | 76 | blue = 0; |
| emanuel22e | 0:47321458789d | 77 | Thread::wait(300); |
| emanuel22e | 0:47321458789d | 78 | red = 0; |
| emanuel22e | 0:47321458789d | 79 | green = 1; |
| emanuel22e | 0:47321458789d | 80 | blue = 0; |
| emanuel22e | 0:47321458789d | 81 | Thread::wait(300); |
| emanuel22e | 0:47321458789d | 82 | red = 0; |
| emanuel22e | 0:47321458789d | 83 | green = 0; |
| emanuel22e | 0:47321458789d | 84 | blue = 1; |
| emanuel22e | 0:47321458789d | 85 | Thread::wait(300); |
| emanuel22e | 0:47321458789d | 86 | } |
| emanuel22e | 1:4fd1a4e54648 | 87 | } |
| emanuel22e | 0:47321458789d | 88 | void t2() { |
| emanuel22e | 1:4fd1a4e54648 | 89 | /* |
| emanuel22e | 0:47321458789d | 90 | FILE *wave_file; |
| emanuel22e | 0:47321458789d | 91 | //open wav file and play it |
| emanuel22e | 1:4fd1a4e54648 | 92 | wave_file=fopen("/sd/mario_sound.wav","r"); |
| emanuel22e | 0:47321458789d | 93 | waver.play(wave_file); |
| emanuel22e | 0:47321458789d | 94 | fclose(wave_file); |
| emanuel22e | 0:47321458789d | 95 | //end of program |
| emanuel22e | 0:47321458789d | 96 | Thread::wait(500); |
| emanuel22e | 1:4fd1a4e54648 | 97 | */ |
| emanuel22e | 1:4fd1a4e54648 | 98 | speaker.period(1.0/500.0); // 500hz period |
| emanuel22e | 1:4fd1a4e54648 | 99 | speaker =0.5; //50% duty cycle - max volume |
| emanuel22e | 1:4fd1a4e54648 | 100 | Thread::wait(3); |
| emanuel22e | 1:4fd1a4e54648 | 101 | speaker=0.0; // turn off audio |
| emanuel22e | 1:4fd1a4e54648 | 102 | Thread::wait(2); |
| emanuel22e | 0:47321458789d | 103 | } |
| emanuel22e | 1:4fd1a4e54648 | 104 | void t3() { |
| emanuel22e | 1:4fd1a4e54648 | 105 | while (1) { |
| emanuel22e | 1:4fd1a4e54648 | 106 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 107 | uLCD.text_width(2); //4X size text |
| emanuel22e | 1:4fd1a4e54648 | 108 | uLCD.text_height(2); |
| emanuel22e | 1:4fd1a4e54648 | 109 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 110 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 111 | uLCD.color(RED); |
| emanuel22e | 1:4fd1a4e54648 | 112 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 113 | for (int i=10; i>=0; --i) { |
| emanuel22e | 1:4fd1a4e54648 | 114 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 115 | uLCD.locate(1,2); |
| emanuel22e | 1:4fd1a4e54648 | 116 | uLCD.printf("%2D",i); |
| emanuel22e | 1:4fd1a4e54648 | 117 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 118 | Thread::wait(750); |
| emanuel22e | 1:4fd1a4e54648 | 119 | } |
| emanuel22e | 1:4fd1a4e54648 | 120 | //u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 121 | Thread::wait(1000); |
| emanuel22e | 1:4fd1a4e54648 | 122 | } |
| emanuel22e | 1:4fd1a4e54648 | 123 | } |
| emanuel22e | 1:4fd1a4e54648 | 124 | void t4() { |
| emanuel22e | 1:4fd1a4e54648 | 125 | while (1) { |
| emanuel22e | 1:4fd1a4e54648 | 126 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 127 | uLCD.text_width(2); //4X size text |
| emanuel22e | 1:4fd1a4e54648 | 128 | uLCD.text_height(2); |
| emanuel22e | 1:4fd1a4e54648 | 129 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 130 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 131 | uLCD.color(GREEN); |
| emanuel22e | 1:4fd1a4e54648 | 132 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 133 | for (int i=10; i>=0; --i) { |
| emanuel22e | 1:4fd1a4e54648 | 134 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 135 | uLCD.locate(1,4); |
| emanuel22e | 1:4fd1a4e54648 | 136 | uLCD.printf("%2D",i); |
| emanuel22e | 1:4fd1a4e54648 | 137 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 138 | Thread::wait(1000); |
| emanuel22e | 1:4fd1a4e54648 | 139 | } |
| emanuel22e | 1:4fd1a4e54648 | 140 | //u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 141 | Thread::wait(1200); |
| emanuel22e | 1:4fd1a4e54648 | 142 | } |
| emanuel22e | 1:4fd1a4e54648 | 143 | } |
| emanuel22e | 0:47321458789d | 144 | int main() { |
| emanuel22e | 1:4fd1a4e54648 | 145 | //thread1.start(t1); |
| emanuel22e | 0:47321458789d | 146 | thread2.start(t2); |
| emanuel22e | 1:4fd1a4e54648 | 147 | thread3.start(t3); |
| emanuel22e | 1:4fd1a4e54648 | 148 | thread4.start(t4); |
| emanuel22e | 1:4fd1a4e54648 | 149 | char bred=0; |
| emanuel22e | 1:4fd1a4e54648 | 150 | char bgreen=0; |
| emanuel22e | 1:4fd1a4e54648 | 151 | char bblue=0; |
| emanuel22e | 1:4fd1a4e54648 | 152 | red = green = blue = 0; |
| emanuel22e | 0:47321458789d | 153 | while(1) { |
| emanuel22e | 1:4fd1a4e54648 | 154 | if (bluemod.readable()) { |
| emanuel22e | 1:4fd1a4e54648 | 155 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 156 | |
| emanuel22e | 1:4fd1a4e54648 | 157 | if (bluemod.getc()=='!') { |
| emanuel22e | 1:4fd1a4e54648 | 158 | if (bluemod.getc()=='C') { //color data packet |
| emanuel22e | 1:4fd1a4e54648 | 159 | bred = bluemod.getc(); // RGB color values |
| emanuel22e | 1:4fd1a4e54648 | 160 | bgreen = bluemod.getc(); |
| emanuel22e | 1:4fd1a4e54648 | 161 | bblue = bluemod.getc(); |
| emanuel22e | 1:4fd1a4e54648 | 162 | if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) { //checksum OK? |
| emanuel22e | 1:4fd1a4e54648 | 163 | red = bred/255.0; //send new color to RGB LED PWM outputs |
| emanuel22e | 1:4fd1a4e54648 | 164 | green = bgreen/255.0; |
| emanuel22e | 1:4fd1a4e54648 | 165 | blue = bblue/255.0; |
| emanuel22e | 1:4fd1a4e54648 | 166 | } |
| emanuel22e | 1:4fd1a4e54648 | 167 | } |
| emanuel22e | 1:4fd1a4e54648 | 168 | } |
| emanuel22e | 1:4fd1a4e54648 | 169 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 170 | } |
| emanuel22e | 1:4fd1a4e54648 | 171 | |
| emanuel22e | 1:4fd1a4e54648 | 172 | |
| emanuel22e | 1:4fd1a4e54648 | 173 | |
| emanuel22e | 1:4fd1a4e54648 | 174 | |
| emanuel22e | 1:4fd1a4e54648 | 175 | |
| emanuel22e | 1:4fd1a4e54648 | 176 | |
| emanuel22e | 1:4fd1a4e54648 | 177 | |
| emanuel22e | 1:4fd1a4e54648 | 178 | /* |
| emanuel22e | 1:4fd1a4e54648 | 179 | red = 0; |
| emanuel22e | 1:4fd1a4e54648 | 180 | green = 0; |
| emanuel22e | 1:4fd1a4e54648 | 181 | blue = 0; |
| emanuel22e | 1:4fd1a4e54648 | 182 | while (1) { |
| emanuel22e | 1:4fd1a4e54648 | 183 | red = 1; |
| emanuel22e | 1:4fd1a4e54648 | 184 | green = 0; |
| emanuel22e | 1:4fd1a4e54648 | 185 | blue = 0; |
| emanuel22e | 1:4fd1a4e54648 | 186 | Thread::wait(300); |
| emanuel22e | 1:4fd1a4e54648 | 187 | //wait(.3); |
| emanuel22e | 1:4fd1a4e54648 | 188 | red = 0; |
| emanuel22e | 1:4fd1a4e54648 | 189 | green = 1; |
| emanuel22e | 1:4fd1a4e54648 | 190 | blue = 0; |
| emanuel22e | 1:4fd1a4e54648 | 191 | Thread::wait(300); |
| emanuel22e | 1:4fd1a4e54648 | 192 | //wait(.3); |
| emanuel22e | 1:4fd1a4e54648 | 193 | red = 0; |
| emanuel22e | 1:4fd1a4e54648 | 194 | green = 0; |
| emanuel22e | 1:4fd1a4e54648 | 195 | blue = 1; |
| emanuel22e | 1:4fd1a4e54648 | 196 | Thread::wait(300); |
| emanuel22e | 1:4fd1a4e54648 | 197 | //wait(.3); |
| emanuel22e | 1:4fd1a4e54648 | 198 | |
| emanuel22e | 1:4fd1a4e54648 | 199 | } |
| emanuel22e | 1:4fd1a4e54648 | 200 | */ |
| emanuel22e | 1:4fd1a4e54648 | 201 | /* |
| emanuel22e | 1:4fd1a4e54648 | 202 | FILE *wave_file; |
| emanuel22e | 1:4fd1a4e54648 | 203 | //open wav file and play it |
| emanuel22e | 1:4fd1a4e54648 | 204 | wave_file=fopen("/sd/mario_sound.wav","r"); |
| emanuel22e | 1:4fd1a4e54648 | 205 | waver.play(wave_file); |
| emanuel22e | 1:4fd1a4e54648 | 206 | fclose(wave_file); |
| emanuel22e | 1:4fd1a4e54648 | 207 | //end of program |
| emanuel22e | 1:4fd1a4e54648 | 208 | Thread::wait(500); |
| emanuel22e | 1:4fd1a4e54648 | 209 | */ |
| emanuel22e | 1:4fd1a4e54648 | 210 | |
| emanuel22e | 1:4fd1a4e54648 | 211 | /* |
| emanuel22e | 1:4fd1a4e54648 | 212 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 213 | uLCD.text_width(2); //4X size text |
| emanuel22e | 1:4fd1a4e54648 | 214 | uLCD.text_height(2); |
| emanuel22e | 1:4fd1a4e54648 | 215 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 216 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 217 | uLCD.color(RED); |
| emanuel22e | 1:4fd1a4e54648 | 218 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 219 | for (int i=10; i>=0; --i) { |
| emanuel22e | 1:4fd1a4e54648 | 220 | u_mutex.lock(); |
| emanuel22e | 1:4fd1a4e54648 | 221 | uLCD.locate(1,2); |
| emanuel22e | 1:4fd1a4e54648 | 222 | uLCD.printf("%2D",i); |
| emanuel22e | 1:4fd1a4e54648 | 223 | u_mutex.unlock(); |
| emanuel22e | 1:4fd1a4e54648 | 224 | Thread::wait(750); |
| emanuel22e | 1:4fd1a4e54648 | 225 | } |
| emanuel22e | 1:4fd1a4e54648 | 226 | Thread::wait(1000); |
| emanuel22e | 1:4fd1a4e54648 | 227 | */ |
| emanuel22e | 1:4fd1a4e54648 | 228 | |
| emanuel22e | 1:4fd1a4e54648 | 229 | /* |
| emanuel22e | 1:4fd1a4e54648 | 230 | speaker.period(1.0/500.0); // 500hz period |
| emanuel22e | 1:4fd1a4e54648 | 231 | speaker =0.5; //50% duty cycle - max volume |
| emanuel22e | 1:4fd1a4e54648 | 232 | Thread::wait(10); |
| emanuel22e | 1:4fd1a4e54648 | 233 | speaker=0.0; // turn off audio |
| emanuel22e | 1:4fd1a4e54648 | 234 | Thread::wait(10); |
| emanuel22e | 1:4fd1a4e54648 | 235 | */ |
| emanuel22e | 0:47321458789d | 236 | |
| emanuel22e | 0:47321458789d | 237 | } |
| emanuel22e | 0:47321458789d | 238 | } |