Complete Build

Dependencies:   4DGL-uLCD-SE1 Motor SDFileSystem X_NUCLEO_53L0A1 mbed-rtos mbed BotwithWavePlayerLevel

Fork of BotWithBluetoothLIDARV2 by Brandon Weiner and Carlos Tallard

main.cpp

Committer:
bdragon52
Date:
2017-10-06
Revision:
13:ab6bbdd2447a
Parent:
12:af37c8938aaf
Child:
14:cc2e4fbaffd8

File content as of revision 13:ab6bbdd2447a:

#include "mbed.h"
#include "rtos.h"
#include "uLCD_4DGL.h"
#include "SDFileSystem.h"
#include "wave_player.h"
//nclude "picojpeg.h"

Serial blues(p13,p14);
SDFileSystem sd(p5, p6, p7, p9, "sd"); //SD card

AnalogOut DACout(p18);

wave_player waver(&DACout);
 
PwmOut red(p23);
PwmOut blue(p21);
PwmOut green(p22);

PwmOut myled(LED1);
uLCD_4DGL uLCD(p28,p27,p30);
Mutex ourMutex;
Thread thread2;
Thread thread3;
Thread thread4;
Thread thread5;
 float y=0.0;
 int c=80;
 int d=1;
char bnum=0;
char current='1';
int color=YELLOW;
 
void t2() {
    while (true) {
       int a=20;
       int r=8;
       
       ourMutex.lock();
       uLCD.background_color(BLACK);
       uLCD.cls();
       uLCD.filled_circle(a, 80-(y*80)+25, r, BLUE);
       uLCD.line(3,25,13,25,RED);
       uLCD.line(3,105,13,105,RED);
       ourMutex.unlock();
      
       //while(b<100){
         //  uLCD.filled_circle(a, b, r, BLUE);
         //  b=b+1;
         //  uLCD.filled_circle(a, b-1, r, BLACK);
         //  uLCD.filled_circle(a, b, r, BLUE);
         //  Thread::wait(1000.0*0.002);
         //  }
        //while(b>50){
         //  uLCD.filled_circle(a, b, r, BLUE);
         //  b=b-1;
          // uLCD.filled_circle(a, b+2, r, BLACK);
          // uLCD.filled_circle(a, b, r, BLUE);
           //Thread::wait(1000.0*0.002);
          // }
       
       
        Thread::wait(1000.0*0.02);
        
    }
}
 
 void t3() {
    while (true) {
         FILE *wave_file;
     
         wave_file=fopen("/sd/Bee Gees - Stayin' Alive.wav","r");
         waver.play(wave_file);
         fclose(wave_file);
         Thread::wait(1000);
    }
}

void t4() {
    while (true) {
          
        ourMutex.lock();
        
        if(c==70){
            d=20;
            }
         if(c==110){
            d=-20;
            }
       
        uLCD.filled_circle(c, 64 , 10, WHITE);
        uLCD.filled_circle(c, 64 , 8, color);
        Thread::wait(50);
         uLCD.filled_circle(c, 64 , 10, BLACK);
        c=c+d;
        uLCD.filled_circle(c, 64 , 10, color);
        uLCD.filled_circle(c, 64 , 8, WHITE);
        Thread::wait(50);
        uLCD.filled_circle(c, 64 , 10, BLACK);
        
        ourMutex.unlock();
        Thread::wait(50);
    }
}
 
 
void t5(){
    
    while(true){
    
         
         if(blues.readable()==1){
             ourMutex.lock();
         if (blues.getc()=='!') {
            if (blues.getc()=='B') { //button data
                bnum = blues.getc(); //button number
                if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4
                   current=bnum;
                   }
        }
        
        }
        
        if(current=='1'){
            color=YELLOW;
            }
         if(current=='2'){
            color=BLUE;
            }
         if(current=='3'){
            color=0x551A8B;
            }
         if(current=='4'){
            color=GREEN;
            }
    
    ourMutex.unlock();
    
    Thread::wait(50);
    }
    
    }



 
int main() {
    thread2.start(t2);
    thread3.start(t3);
    thread4.start(t4);
    thread5.start(t5);
    
    while(1) {
        for(double x=0.0; x <= 3.14159; x = x + 0.0314159) {
            y = sin(x); 
            red= y*y*y;
            blue= y*y*y;
            green= y*y*y;
            Thread::wait(1000.0*.025);
        }
        red= 0.0;
        blue= 0.0;
        green= 0.0;
        Thread::wait(1000.0*2.5);
    }
    
    
    
    
}