inital commit
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem2 PinDetect MMA8452
Diff: main.cpp
- Revision:
- 9:08886cc06a5d
- Parent:
- 7:71e9ee360b90
- Child:
- 10:5bd6abd66d12
--- a/main.cpp Sun Dec 12 20:44:48 2021 +0000 +++ b/main.cpp Sun Dec 12 23:11:48 2021 +0000 @@ -9,7 +9,7 @@ #include <vector> DigitalOut myled(LED1); -Serial blue(p28,p27); +RawSerial blue(p28,p27); SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card uLCD_4DGL uLCD(p13,p14,p11); @@ -30,7 +30,7 @@ wave_player waver(&DACout); bool playing = false; -bool play = 0; +bool play = 1; bool menu1 = 0; bool inmenu=0; int currentsong = 0; @@ -74,7 +74,7 @@ uLCD.cls(); uLCD.locate(1,1); uLCD.printf("%s",songList[currentsong].substr(0,songList[currentsong].find(".wav"))); - if(!play) + if(play) { //play @@ -139,15 +139,17 @@ { //add playpause and skip features here Speaker.lock(); - if(play) + if(!menu1) { - playing = false; + playing=!playing; + play=!playing; } else { - playing = true; + playing=!playing; + Thread::wait(500); + playing=!playing; } - play=!play; myled=play; Speaker.unlock(); Thread::wait(10); @@ -155,6 +157,8 @@ void skipThread() { //add skip features + + Speaker.lock(); if(currentsong<songcount-1) { currentsong++; @@ -163,14 +167,16 @@ { currentsong=0; } - if(!menu) + if(!menu1) { playing=true; play=true; } + Speaker.unlock(); } void backThread() { + Speaker.lock(); if(currentsong!=0) { currentsong--; @@ -179,11 +185,12 @@ { currentsong=songcount-1; } - if(!menu) + if(!menu1) { playing=true; play=true; } + Speaker.unlock(); } void menuThread() { @@ -192,13 +199,95 @@ void BlueThread(void const *argument) { //add bluetooth control code here + char bnum =0; + char bhit=0; while(1) { - if(blue.readable()) + + if(blue.readable()&&blue.writeable()) { - + if (blue.getc()=='!') { + if (blue.getc()=='B') { //button data + bnum = blue.getc(); //button number + bhit=blue.getc(); + if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4 + { + LCD.lock(); + uLCD.printf("%s", "test lol"); + LCD.unlock(); + switch (bnum) + { + case '1': //number button 1 //add playpause and skip features here + if (bhit=='1') { + Speaker.lock(); + if(play) + { + playing = false; + } + else + { + playing = true; + } + play=!play; + myled=play; + Speaker.unlock(); + Thread::wait(10); + } + break; + case '2': //number button 2 + if (bhit=='1') { + mentex.lock(); + if(currentsong<songcount-1) + { + currentsong++; + } + else + { + currentsong=0; + } + if(!menu) + { + playing=true; + play=true; + } + mentex.unlock(); + } + break; + case '3': //number button 3 + if (bhit=='1') { + mentex.lock(); + if(currentsong!=0) + { + currentsong--; + } + else + { + currentsong=songcount-1; + } + if(!menu) + { + playing=true; + play=true; + } + mentex.unlock(); + } + break; + case '4': //number button 4 + if (bhit=='1') { + mentex.lock(); + menu1=!menu1; + mentex.unlock(); + } + break; + default: + break; + } + } + + } } - Thread::wait(100); + } + Thread::wait(1000); } } void IMUThread(void const *argument)