W R / Mbed 2 deprecated 4180_Final_Project

Dependencies:   mbed wave_player mbed-rtos 4180Final SDFileSystem

main.cpp

Committer:
trmontgomery
Date:
2020-04-27
Revision:
8:1b8ab0d75463
Parent:
1:e14104308237

File content as of revision 8:1b8ab0d75463:

#include "init.h"

Timer play_time; 
volatile float val; 
float score1 = 0; 
int curRound = 1;
float round_time = 15.0;  

void play_draw(){
     uLCD.background_color(GREEN);
     uLCD.cls();
     uLCD.filled_rectangle(0, 0, 200, 15, RED);
     // header
     uLCD.color(BLACK);
     uLCD.locate(5,0);
     uLCD.text_height(2);
     uLCD.text_width(2);
     uLCD.textbackground_color(RED);
     uLCD.printf("PLAY");
     uLCD.text_height(1);
     uLCD.text_width(1);
     uLCD.locate(14,1);
     uLCD.printf("Rnd%1d", curRound);
     // Scores headers
     uLCD.textbackground_color(GREEN);
     uLCD.color(BLUE);
     uLCD.locate(5,3);
     uLCD.printf("Player 1:");
     uLCD.color(PURPLE);
     uLCD.locate(5,11);
     uLCD.printf("Player 2:");
     // Scores
     uLCD.text_height(4);
     uLCD.text_width(4); 
} 

void update_LEDS(){
    if(val <= 2.5){
        led_strip = 0b100000; 
    } else if (2.5 > val && val < 5){
        led_strip = 0b110000; 
    } else if (val > 5 && val < 7.5){
        led_strip = 0b111000; 
    } else if (val > 7.5 && val < 10){
        led_strip = 0b111100; 
    } else if (val > 10 && val < 12.5){
        led_strip = 0b111110; 
    } else if (val > 12.5 && val < 15){
        led_strip = 0b111111; 
    } else {
        led_strip = 0; 
    }
    Thread::wait(0.2); 
}

void read_microphone(){
    //8Mhz sample
    val = int(abs((mymicrophone - (0.67/3.3)))*500.0);
    Thread::wait(8); 
}

void time_bar(){
        /*
            // Time bar
            double roundTime = 15.0;  // in secs
            int length = (int) ( (double)curTime / roundTime * 127.0);
            uLCD.filled_rectangle(0, 65, length, 85, DGREEN);
            if (length >= 127) {
                nextRound();
            }
            curTime++;
            */
}
 
void play() {
     play_draw(); 
     play_time.reset(); 
     play_time.start(); 
     Thread t1(update_LEDS);
     Thread t2(read_microphone);
     while (play_time.read() < round_time*1000) {
        /*
        if (myNav.fire()) { //open pause menu 
            uLCD.filled_rectangle(60, 68, 65, 82, GREEN); //the pause draw functions shoudl be contained within pause
            uLCD.filled_rectangle(70, 68, 75, 82, GREEN);
            //join threads?
            Thread::wait(100);
            //pause();
        }*/
        
        //if (int(play_time.read()) % 8 == 0) { //Use an 8kHz audio sample rate (phone quality audio);
            //tick = get_sound(); // this should be added to every iter
            score1 += val; 
            //score2 = curTime+2000;
            
            ///DRAWS SCORES ON SCREEN
            uLCD.color(BLUE);
            uLCD.locate(0,1);
            uLCD.printf("%4d", val);
            uLCD.color(PURPLE);
            uLCD.locate(0,3);
            uLCD.printf("%4d", score1);
                
    
        Thread::wait(100);
    }
}
 
int main()
{
    play();
}