4180 Final
Dependencies: mbed wave_player mbed-rtos 4180Final SDFileSystem
Diff: main.cpp
- Revision:
- 19:537afb30777c
- Parent:
- 18:460a8024608b
- Child:
- 20:a46d5d9c21cd
--- a/main.cpp Wed Apr 29 21:16:27 2020 +0000 +++ b/main.cpp Wed Apr 29 21:32:17 2020 +0000 @@ -1,8 +1,3 @@ -// TODO: -// - Add actual way to calulate scores (in play() or add helper method) -// - Add more inputs/outputs -// - add pot to increase selector size -// - add sound #include "mbed.h" #include "uLCD_4DGL.h" #include "Nav_Switch.h" @@ -17,17 +12,8 @@ #define LED_GLOBAL 31 // brightness 0-31 #define LED_FREQ 500000 // spi -Thread thread1, thread2; -//Thread t1(read_mic); -//Thread t2(update_lcd_score); -Thread t1; -Thread t2; -<<<<<<< working copy -Thread t3; -Nav_Switch myNav(p9, p6, p7, p5, p8); //pin order on Sparkfun breakout -======= +//Hardware Init Nav_Switch myNav(p21, p22, p23, p24, p25); //pin order on Sparkfun breakout ->>>>>>> merge rev uLCD_4DGL uLCD(p28, p27, p30); // serial tx, serial rx, reset pin; SDFileSystem sd(p11, p12, p13, p10, "sd"); microphone mymic1(p15); @@ -37,24 +23,16 @@ PwmOut myled(LED1); PwmOut myled2(LED2); PwmOut myled3(LED3); -<<<<<<< working copy -BusOut led_strip1(p21,p22,p23); -BusOut led_strip2(p24,p25,p26); -//SPI SPI spi(p5, p6, p7); -//bool to check if ledstrip is done recieving frame before terminating thread -volatile bool stopLedStrip = false; -======= -//BusOut led_strip1(p21,p22,p23); -//BusOut led_strip2(p24,p25,p26); ->>>>>>> merge rev +//GLOBALS +volatile bool stopLedStrip = false; //bool to check if ledstrip is done recieving frame before terminating thread + //Mutexs Mutex lcd_mutex; Mutex lightLEDS_mutex; -// Globals int rounds = 3; int curRound = 1; volatile int score1 = 0; @@ -70,12 +48,10 @@ volatile int micScore1 = 0; volatile int micScore2 = 0; int playType = 0; +Thread thread1, thread2, t1, t2, t3; -//Global Array int ledArr[LED_NUM] = {0}; -//#include "play.h" - // Stuff for sound unsigned char *music = NULL; wave_player waver(&DACout); @@ -101,11 +77,9 @@ void playMenuMusic() { if (playMusic) { music = (unsigned char*) fireflies; -// myled2 = 1; DACout.write(music[sIndx++] / 255.0); if(sIndx > 120000) { sIndx = 0; -// myled2 = 0; } } else { DACout.write(0.0); @@ -438,7 +412,6 @@ } } -<<<<<<< working copy //new update led function void dotStar () { @@ -532,23 +505,7 @@ lightLEDS_mutex.unlock(); } -======= -/* ->>>>>>> merge rev -void update_leds(){ - switch (loud1){ - case 10: led_strip1 = 1; break; - case 20: led_strip1 = 3; break; - case 30: led_strip1 = 7; break; - } - switch (loud2){ - case 10: led_strip2 = 1; break; - case 20: led_strip2 = 3; break; - case 30: led_strip2 = 7; break; - } - //Thread::wait(200); -} -*/ + void update_score(){ if (mic_reading1 > 16) { loud1++; //if the player screams loudly for enough times it increases your score @@ -567,11 +524,9 @@ mic_reading2 = int(abs((mymic2 - (0.67/3.3)))*500.0); update_score(); //update_leds(); -<<<<<<< working copy + update_ledArr(); //updates an array that tells what led should be on -======= ->>>>>>> merge rev - + Thread::wait(500); } } @@ -622,24 +577,22 @@ //reset ledstrip resetLedArr(); resetLedStrip(); - //delete thread methods if threads do not work// + t1.start(read_mic); t2.start(update_lcd_score); t3.start(dotStar); //new thread that sends frames to led strip - //mic.attach(&read_mic, 1.0/8000.0); + while (1) { timer = 0; // Blinking pause button while (timer<25) { - //mic.attach(&read_mic, 1.0/8000.0); - //Threread_mic(); if (myNav.fire()) { lcd_mutex.lock(); uLCD.filled_rectangle(60, 68, 65, 82, GREEN); uLCD.filled_rectangle(70, 68, 75, 82, GREEN); wait(.1); - //**delete mutexs ad thread methods if threads do not work**// + stopLedStrip = true; lcd_mutex.lock(); t1.terminate(); @@ -647,28 +600,12 @@ t1.join(); t2.join(); t3.join(); - //******************************************************// + stopLedStrip = false; pause(); } lcd_mutex.lock(); //remove if thread doesnt work if (timer % 25 == 0) { - //score1 += getScore1(); - //score2 += getScore2(); - - //*****uncomment if threads do not work********// - //update_score(); - //update_leds(); - //uLCD.color(BLUE); - //uLCD.locate(0,1); - //uLCD.printf("%4d", mic_reading1); // change to score1 - //uLCD.printf("%4d", mic_reading2); //change to score 2 - //uLCD.color(PURPLE); - //uLCD.locate(0,3); - //uLCD.printf("%4d", mic_reading2); - //uLCD.printf("%4d", score2); - //*******************************************// - // Time bar double roundTime = 15.0; // in secs int length = (int) ( (double)curTime / roundTime * 127.0);