Test

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Fork of rtos_basic by mbed official

Committer:
elee328
Date:
Fri Oct 13 22:24:05 2017 +0000
Revision:
12:0db14346f701
Parent:
11:0309bef74ba8
asd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
mbed_official 11:0309bef74ba8 2 #include "rtos.h"
elee328 12:0db14346f701 3 #include "wave_player.h"
elee328 12:0db14346f701 4 #include "SDFileSystem.h"
elee328 12:0db14346f701 5 #include "uLCD_4DGL.h"
emilmont 1:491820ee784d 6
emilmont 1:491820ee784d 7 DigitalOut led1(LED1);
emilmont 1:491820ee784d 8 DigitalOut led2(LED2);
elee328 12:0db14346f701 9
elee328 12:0db14346f701 10 AnalogOut DACout(p18);
elee328 12:0db14346f701 11 wave_player waver(&DACout);
elee328 12:0db14346f701 12 uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin;
elee328 12:0db14346f701 13 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
elee328 12:0db14346f701 14 PwmOut red(p25);
elee328 12:0db14346f701 15 PwmOut green(p24);
elee328 12:0db14346f701 16 PwmOut blue(p23);
elee328 12:0db14346f701 17
elee328 12:0db14346f701 18
elee328 12:0db14346f701 19
elee328 12:0db14346f701 20 Mutex lcd_mutex;
elee328 12:0db14346f701 21
elee328 12:0db14346f701 22 FILE *wave_file;
elee328 12:0db14346f701 23
elee328 12:0db14346f701 24 int height = 15;
elee328 12:0db14346f701 25 int height2 = 15;
elee328 12:0db14346f701 26
elee328 12:0db14346f701 27 FILE *fp;
elee328 12:0db14346f701 28 void wav_thread() {
elee328 12:0db14346f701 29
emilmont 1:491820ee784d 30 while (true) {
elee328 12:0db14346f701 31 bool play = true;
elee328 12:0db14346f701 32 int vol = 1;
elee328 12:0db14346f701 33 fp = fopen("/sd/wavfiles/tt.wav", "r");
elee328 12:0db14346f701 34 waver.play(fp, &play, &vol);
mbed_official 11:0309bef74ba8 35 Thread::wait(1000);
elee328 12:0db14346f701 36
elee328 12:0db14346f701 37
emilmont 1:491820ee784d 38 }
emilmont 1:491820ee784d 39 }
elee328 12:0db14346f701 40 void lcd_thread1()
elee328 12:0db14346f701 41 {
elee328 12:0db14346f701 42 while (true)
elee328 12:0db14346f701 43 {
elee328 12:0db14346f701 44 for (int x = 0; x < 13; x++)
elee328 12:0db14346f701 45 {
elee328 12:0db14346f701 46 lcd_mutex.lock();
elee328 12:0db14346f701 47 uLCD.filled_circle(25,height,15,BLACK);
elee328 12:0db14346f701 48 height += 7;
elee328 12:0db14346f701 49 uLCD.filled_circle(25,height,15,WHITE);
elee328 12:0db14346f701 50 lcd_mutex.unlock();
elee328 12:0db14346f701 51 Thread::wait(100);
elee328 12:0db14346f701 52 }
elee328 12:0db14346f701 53 for (int x = 0; x < 13; x++)
elee328 12:0db14346f701 54 {
elee328 12:0db14346f701 55 lcd_mutex.lock();
elee328 12:0db14346f701 56 uLCD.filled_circle(25,height,15,BLACK);
elee328 12:0db14346f701 57 height -= 7;
elee328 12:0db14346f701 58 uLCD.filled_circle(25,height,15,WHITE);
elee328 12:0db14346f701 59 lcd_mutex.unlock();
elee328 12:0db14346f701 60 Thread::wait(100);
elee328 12:0db14346f701 61 }
elee328 12:0db14346f701 62 }
elee328 12:0db14346f701 63 }
elee328 12:0db14346f701 64 void lcd_thread2()
elee328 12:0db14346f701 65 {
elee328 12:0db14346f701 66 while (true)
elee328 12:0db14346f701 67 {
elee328 12:0db14346f701 68 for (int x = 0; x < 13; x++)
elee328 12:0db14346f701 69 {
elee328 12:0db14346f701 70 lcd_mutex.lock();
elee328 12:0db14346f701 71 uLCD.filled_circle(60,height2,15,BLACK);
elee328 12:0db14346f701 72 height2 += 7;
elee328 12:0db14346f701 73 uLCD.filled_circle(60,height2,15,WHITE);
elee328 12:0db14346f701 74 lcd_mutex.unlock();
elee328 12:0db14346f701 75 Thread::wait(100);
elee328 12:0db14346f701 76 }
elee328 12:0db14346f701 77 for (int x = 0; x < 13; x++)
elee328 12:0db14346f701 78 {
elee328 12:0db14346f701 79 lcd_mutex.lock();
elee328 12:0db14346f701 80 uLCD.filled_circle(60,height2,15,BLACK);
elee328 12:0db14346f701 81 height2 -= 7;
elee328 12:0db14346f701 82 uLCD.filled_circle(60,height2,15,WHITE);
elee328 12:0db14346f701 83 lcd_mutex.unlock();
elee328 12:0db14346f701 84 Thread::wait(100);
elee328 12:0db14346f701 85 }
elee328 12:0db14346f701 86 }
elee328 12:0db14346f701 87 }
emilmont 1:491820ee784d 88
emilmont 1:491820ee784d 89 int main() {
elee328 12:0db14346f701 90
elee328 12:0db14346f701 91
elee328 12:0db14346f701 92
elee328 12:0db14346f701 93
elee328 12:0db14346f701 94 //uLCD.cls();
elee328 12:0db14346f701 95
elee328 12:0db14346f701 96 Thread thread1;
elee328 12:0db14346f701 97 Thread thread2;
elee328 12:0db14346f701 98 Thread thread3;
elee328 12:0db14346f701 99 thread1.start(lcd_thread2);
elee328 12:0db14346f701 100 thread2.start(lcd_thread1);
elee328 12:0db14346f701 101 thread3.start(wav_thread);
emilmont 1:491820ee784d 102
emilmont 1:491820ee784d 103 while (true) {
elee328 12:0db14346f701 104 for (float x=0.45; x >= 0; x -= 0.025) {
elee328 12:0db14346f701 105 red = x;
elee328 12:0db14346f701 106 green = x;
elee328 12:0db14346f701 107 blue = x;
elee328 12:0db14346f701 108 Thread::wait(100);
elee328 12:0db14346f701 109 }
elee328 12:0db14346f701 110 for (float x = 0; x <= 0.45; x += 0.025) {
elee328 12:0db14346f701 111 red = x;
elee328 12:0db14346f701 112 green = x;
elee328 12:0db14346f701 113 blue = x;
elee328 12:0db14346f701 114 Thread::wait(100);
elee328 12:0db14346f701 115 }
emilmont 1:491820ee784d 116 }
emilmont 1:491820ee784d 117 }