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
Diff: main.cpp
- Revision:
- 8:17ac4f255e4b
- Parent:
- 7:bf1bb278bdec
- Child:
- 9:b49b975d102f
--- a/main.cpp Mon Oct 03 18:35:19 2016 +0000
+++ b/main.cpp Mon Oct 03 21:12:00 2016 +0000
@@ -1,7 +1,6 @@
#include "mbed.h"
#include "rtos.h"
#include "uLCD_4DGL.h"
-#include "LSM9DS1.h"
#include "SDFileSystem.h"
#include "wave_player.h"
@@ -11,7 +10,7 @@
DigitalOut green(p22);
/*uLCD instantiation*/
-uLCD_4DGL uLCD(p28,p27,p29); // serial tx, serial rx, reset pin;
+uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
Mutex mutex;
/* wave player instantiation*/
@@ -21,35 +20,45 @@
DigitalOut led1(LED1);
DigitalOut led2(LED2);
+DigitalOut led4(LED4);
/* makes different colored squares the same color as the shiftbright*/
void lcd_thread1(void const *args) {
- int color = 0xFFC0CB; //initially pink
while (true) {
- if (blue == 1) { color = 0x0000FF; }
- else if (red === 1) { color = 0xFF0000; }
- else if (green == 1) { color = 0x008000; }
+ if (green == 1) {
mutex.lock();
- uLCD.filled_rectangle(5, 64, 84, 25, color);
+ //uLCD.cls();
+ uLCD.filled_rectangle(64-25, 64-25, 64+25, 64+25, 0xff66cc);
mutex.unlock();
+ //Thread::wait(1000);
+ }
}
}
/*makes different colored circle every time the bell sound sounds*/
void lcd_thread2(void const *args) {
- int color2 = 0xFFC0CB;
+ while (true) {
+ if (blue == 1) {
+ mutex.lock();
+ //uLCD.cls();0x336600
+ uLCD.filled_rectangle(64-25, 64-25, 64+25, 64+25, 0x336600);
+ mutex.unlock();
+ //Thread::wait(1000);
+ }
+ }
}
/*play wav file on sd and when playing led1 turns on*/
void wav_thread3(void const *args) {
- while (true) {
+ //led2 = 1;
+ while (1) {
FILE *wave_file;
- wave_file=fopen("/sd/wavfiles/Store_Door_Chime-Mike_Koenig-570742973.wav","r");
+ wave_file=fopen("/sd/wavfiles/wreck.wav","r");
waver.play(wave_file);
- led1 = 1;
+ //led1 = 1;
fclose(wave_file);
- led1 = 0;
- Thread::wait(500);
+ //Thread::wait(1000);
+ //led1 = 0;
}
}
@@ -59,27 +68,22 @@
blue = 1;
green = 0;
- wait(1);
+ Thread::wait(1000);
red = 0;
blue = 0;
green = 1;
- wait(1);
-
- red = 1;
- blue = 0;
- green = 0;
-
- wait(1);
+ Thread::wait(1000);
}
}
int main() {
- //Thread thread(thread1);
-
- /*while (true) {
- led1 = !led1;
- Thread::wait(500);
- }*/
+ Thread thread1(lcd_thread1);
+ Thread thread2(lcd_thread2);
+ Thread thread3(wav_thread3);
+ Thread thread4(light_thread4);
+ //led4 = 1;
+ //Thread thread(led2_thread);
+ while(1);
}
