Lab 3 Part 4
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem
Diff: main.cpp
- Revision:
- 13:8987c75dfe41
- Parent:
- 12:94b16c66c09a
- Child:
- 14:ae63fb7c2d06
diff -r 94b16c66c09a -r 8987c75dfe41 main.cpp --- a/main.cpp Thu Feb 25 18:30:28 2021 +0000 +++ b/main.cpp Thu Feb 25 19:18:25 2021 +0000 @@ -5,7 +5,9 @@ #include "SDFileSystem.h" #include "wave_player.h" -int setting = 1; +InterruptIn data(p14); + +char setting = '1'; BusOut myled(LED1,LED2,LED3,LED4); @@ -57,17 +59,44 @@ stdio_mutex.unlock(); } +/* Interrupt */ +void set() +{ + char bnum; + if (blue.readable() && blue.getc()=='!') { + if (blue.getc()=='B') { //button data + bnum = blue.getc(); //button number + if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4 + setting = bnum;// Set new setting + } + } +} /* Threads */ void led_thread() { + //char bnum = setting; while(1) { - bLED = 0; - rLED = 1; - Thread::wait(750); - rLED = 0; - bLED = 1; - Thread::wait(750); + if(setting == '1') { + bLED = 0; + rLED = 1; + gLED = 0; + Thread::wait(750); + rLED = 0; + bLED = 1; + gLED = 0; + Thread::wait(750); + } + if (setting == '2') { + bLED = 1; + rLED = 1; + gLED = 0; + Thread::wait(750); + rLED = 0; + bLED = 0; + gLED = 1; + Thread::wait(750); + } } } @@ -107,32 +136,29 @@ rLED = 0; gLED = 0; bLED = 0; + char bnum=0; while(1) { if (blue.readable() && blue.getc()=='!') { if (blue.getc()=='B') { //button data bnum = blue.getc(); //button number - if (bnum=='1') //is a number button 1..4 - setting = 1; + if ((bnum>='1')&&(bnum<='4')) { //is a number button 1..4 + setting = bnum;// Change setting based on button input to set start setting. Check for chars break; //turn on/off that num LED + } } } + } + + + //data.rise(&set); thread1.start(led_thread); thread2.start(speaker_thread); thread3.start(lcd1_thread); thread4.start(lcd2_thread); - + while (true) { - Thread::wait(500) - if (blue.readable() && blue.getc()=='!') { - if (blue.getc()=='B') { //button data - bnum = blue.getc(); //button number - if (bnum=='1') //is a number button 1..4 - setting = 1; - break; //turn on/off that num LED - } - } } }