Complete Build

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

Fork of BotWithBluetoothLIDARV2 by Brandon Weiner and Carlos Tallard

Revision:
18:aa7f48962bdb
Parent:
17:2c6549be1ecb
Child:
19:f854f09cf1ab
--- a/main.cpp	Mon Nov 20 01:47:29 2017 +0000
+++ b/main.cpp	Fri Dec 01 03:13:48 2017 +0000
@@ -13,13 +13,11 @@
 AnalogOut DACout(p18);
 wave_player waver(&DACout);
 
-PwmOut speaker(p23);
-
-//BusOut myled(LED1,LED2,LED3,LED4);
 #include "XNucleo53L0A1.h"
 #include <stdio.h>
 Serial pc(USBTX,USBRX);
 DigitalOut shdn(p26);
+
 //I2C sensor pins
 #define VL53L0_I2C_SDA   p28
 #define VL53L0_I2C_SCL   p27
@@ -32,62 +30,21 @@
 Thread siren;
 uint32_t distance;
 int level = 8; //Volume level is turned off
-//wave_file;
 
-void listdir(void) {
-    DIR *d;
-    struct dirent *p;
 
-    d = opendir("/sd");
-    if (d != NULL) {
-        while ((p = readdir(d)) != NULL) {
-            pc.printf(" - %s\r\n", p->d_name);
-        }
-    } else {
-        pc.printf("Could not open directory!\r\n");
-    }
-    closedir(d);
-}
-
+//speaker thread
 void t3(){
- //  int i;
-   pc.printf("Speaker\r\n");
-   listdir();
-   //waver.set_verbosity(1);
- //  FILE *fp = fopen("/sd/myfile2.txt", "w");
- //  fprintf(fp, "Hello World 11/18\n");
- //   fclose(fp);
+   
     while(1){
-        
-        
-/* generate a 500Hz tone using PWM hardware output
-    speaker.period(1.0/500.0); // 500hz period
-    speaker =0.5; //50% duty cycle - max volume
-    wait(3);
-    speaker=0.0; // turn off audio
-    wait(2);
- 
-// generate a short 150Hz tone using PWM hardware output
-// something like this can be used for a button click effect for feedback
-    for (i=0; i<10; i++) {
-        speaker.period(1.0/150.0); // 500hz period
-        speaker =0.25; //25% duty cycle - mid range volume
-        wait(.02);
-        speaker=0.0; // turn off audio
-        wait(0.5);
-    }
-  */ 
-   while(1){
+               
     FILE *wave_file=fopen("/sd/LoudSound.wav","r");
-    
     waver.play(wave_file);
+    fclose(wave_file);
     
-    fclose(wave_file);
-    //Thread::wait(50);
-    }
 }
 }
 
+//lidar thread
 void t2() {
     
     int status;
@@ -106,9 +63,6 @@
         status = board->init_board();
     }
     //loop taking and printing distance
-    
-    bool speakerOn=false;
-    
     while (1) {
         status = board->sensor_centre->get_distance(&distance);
         if (status == VL53L0X_ERROR_NONE) {
@@ -122,15 +76,6 @@
                  } 
             }
         }
-    
-    //LIDAR checks
-    
-   /* if(speakerOn==false && distance<=100) //thread start sound, speakerOn=true;
-    if(speakerOn==true && distance<=100) //certain volume 
-    if(speakerOn==true && distance<50) //higher volume;
-    if(distance>100) //thread stop, speakerOn==false;
-   */ 
-    //siren.start(t3);
     myled=!myled;
     Thread::wait(500);
     }
@@ -138,9 +83,7 @@
     }
 
 
-
-
-
+//bor movement using bluetooth thread
 int main()
 {
     char previousButton='0';
@@ -159,19 +102,14 @@
                 bnum = blue.getc(); //button number
                 bhit = blue.getc(); //1=hit, 0=release
                 current=bnum;  
-                //Thread::wait(250);                 
-                //pc.printf("Button Pressed %c bhit = %c PreviousButton = %c CurrentButton = %c\n\r", bnum, bhit, previousButton, current);
                 previousButton = current; 
-                if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
-                    //myled = bnum - '0'; //current button number will appear on LEDs
+                if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { 
                     switch (bnum) {
                         case '1': //number button 1
                             if (bhit=='1') {
                                 RW.speed(1);
-                                //add hit code here
                             } else {
                                 //add release code here
-                            }
                             break;
                         case '2': //number button 2
                             if (bhit=='1') {
@@ -198,50 +136,39 @@
                             break;
                         case '5': //button 5 up arrow
                             if (bhit=='1') {
-                                //add hit code here
-                                
-                                 RW.speed(1.0);
-                                 LW.speed(1.0);  
-                                
+                                RW.speed(1.0);
+                                LW.speed(1.0);  
                             } else {
-                                
-                                   LW.speed(0); 
-                                  RW.speed(0); 
-                                //add release code here
+                                RW.speed(0); 
+                                LW.speed(0); 
                             }
                             break;
                         case '6': //button 6 down arrow
                             if (bhit=='1') {
-                                 RW.speed(-1.0);
-                                 LW.speed(-1.0);  
+                                RW.speed(-1.0);
+                                LW.speed(-1.0);  
                                 //add hit code here
                             } else {
                                 RW.speed(0);
-                                 LW.speed(0);
-                                //add release code here
+                                LW.speed(0);
                             }
                             break;
                         case '7': //button 7 left arrow
                             if (bhit=='1') {
                                 RW.speed(-1.0);
-                                 LW.speed(1.0);
-                                //add hit code here
+                                LW.speed(1.0);
                             } else {
-                                
                                 RW.speed(0);
-                                 LW.speed(0);
-                                //add release code here
+                                LW.speed(0);
                             }
                             break;
                         case '8': //button 8 right arrow
                             if (bhit=='1') {
                                 RW.speed(1.0);
-                                 LW.speed(-1.0);
-                                //add hit code here
+                                LW.speed(-1.0);
                             } else {
                                 RW.speed(0);
-                                 LW.speed(0);
-                                //add release code here
+                                LW.speed(0);
                             }
                             break;
                         default:
@@ -256,5 +183,5 @@
             Thread::yield();
             
         }
-    
+    }
    } 
\ No newline at end of file