ESD Lab / Mbed 2 deprecated 4180_lab4_Mini_Project

Dependencies:   4DGL-uLCD-SE mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
sheldonfernandes2404
Date:
Tue Mar 10 03:54:34 2015 +0000
Parent:
2:437fc6e9a1c3
Child:
4:403b2f7060c4
Commit message:
added a header file

Changed in this revision

SDFileSystem.lib Show diff for this revision Revisions of this file
Speaker.h Show diff for this revision Revisions of this file
head.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
wave_player/wave_player.cpp Show diff for this revision Revisions of this file
wave_player/wave_player.h Show diff for this revision Revisions of this file
--- a/SDFileSystem.lib	Tue Mar 10 03:04:14 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- a/Speaker.h	Tue Mar 10 03:04:14 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#include "mbed.h"
-// a new class to play a note on Speaker based on PwmOut class
-class Speaker
-{
-public:
-    Speaker(PinName pin) : _pin(pin) {
-// _pin(pin) means pass pin to the Speaker Constructor
-    }
-// class method to play a note based on PwmOut class
-    void PlayNote(float frequency, float duration, float volume) {
-        _pin.period(1.0/frequency);
-        _pin = volume/2.0;
-        wait(duration);
-        _pin = 0.0;
-    }
-
-private:
-    PwmOut _pin;
-};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head.h	Tue Mar 10 03:54:34 2015 +0000
@@ -0,0 +1,299 @@
+#ifndef HEAD_H
+#define HEAD_H
+
+#include "mbed.h"
+#include "mbed.h"
+#include "uLCD_4DGL.h"
+#include "math.h"
+#include "rtos.h"
+#include <string>
+
+#define YELLOW              0xFFFF00
+#define ORANGE              0xffdd76
+#define MECYAN              0x009696
+
+AnalogIn timer(p20);
+Mutex stdio_mutex;
+uLCD_4DGL lcd(p28, p27, p30);
+
+AnalogIn steer(p17);
+AnalogIn force(p16);
+
+volatile int count=30;
+volatile int a=0;
+volatile int cheat=3;
+
+void start()
+{
+    lcd.baudrate(300000);
+    lcd.printf("Need for Speed  :P  \n");
+    lcd.printf("------------------");
+    lcd.printf("1. Rotation Sensor - To steer right or left\n\n");
+    lcd.printf("2. Force Sensor - To speed up\n\n");
+    lcd.printf("3. Touch Sensor - To Cheat (3 times max)\n\n\n");
+    lcd.printf("  Touch to begin!\n");
+}
+
+void forward(void const *args)
+{
+    while(1) {
+        stdio_mutex.lock();
+        if (timer<0.1) {
+            if(count<29 && cheat>0) {
+                ++count;
+                ++count;
+                --cheat;
+            }
+            if(timer<0.1 && cheat<1) {
+                lcd.printf("STOP cheating");
+            }
+        }
+        stdio_mutex.unlock();
+        Thread::wait(400);
+    }
+}
+
+void steering(void const *args)
+{
+    while(1) {
+        stdio_mutex.lock();
+        lcd.cls();
+        a=floor(steer*39);
+        if(a>9) {
+            a=9;
+        }
+        switch(a) {
+            case (1): {
+                lcd.filled_rectangle(0, 98, 9, 110, BLUE);
+                break;
+            }
+            case (2): {
+                lcd.filled_rectangle(14, 98, 23, 110, BLUE);
+                break;
+            }
+            case (3): {
+                lcd.filled_rectangle(28, 98, 37, 110, BLUE);
+                break;
+            }
+            case (4): {
+                lcd.filled_rectangle(42, 98, 51, 110, BLUE);
+                break;
+            }
+            case (5): {
+                lcd.filled_rectangle(56, 98, 65, 110, BLUE);
+                break;
+            }
+            case (6): {
+                lcd.filled_rectangle(70, 98, 79, 110, BLUE);
+                break;
+            }
+            case (7): {
+                lcd.filled_rectangle(84, 98, 93, 110, BLUE);
+                //Thread::wait(200);
+                break;
+            }
+            case (8): {
+                lcd.filled_rectangle(98, 98, 107, 110, BLUE);
+                //  Thread::wait(200);
+                break;
+            }
+            case (9): {
+                lcd.filled_rectangle(112, 98, 121, 110, BLUE);
+                //  Thread::wait(200);
+                break;
+            }
+        }
+        Thread::wait(200);
+        stdio_mutex.unlock();
+
+    }
+}
+
+void obstacle(void const *args)
+{
+    while(1) {
+        stdio_mutex.lock();
+        switch(count) {
+            case (30): {
+                lcd.filled_rectangle(0, 0, 90, 10, RED);
+                break;
+            }
+            case (29): {
+                lcd.filled_rectangle(0, 10, 90, 20, RED);
+                break;
+            }
+            case (28): {
+                lcd.filled_rectangle(0, 20, 90, 30, RED);
+                break;
+            }
+            case (27): {
+                lcd.filled_rectangle(0, 30, 90, 40, RED);
+                break;
+            }
+            case (26): {
+                lcd.filled_rectangle(0, 40, 90, 50, RED);
+                break;
+            }
+            case (25): {
+                lcd.filled_rectangle(0, 50, 90, 60, RED);
+                lcd.filled_rectangle(70, 0, 90, 10, GREEN);
+                break;
+            }
+            case (24): {
+                lcd.filled_rectangle(0, 60, 90, 70, RED);
+                lcd.filled_rectangle(70, 10, 127, 20, GREEN);
+                break;
+            }
+            case (23): {
+                lcd.filled_rectangle(0, 70, 90, 80, RED);
+                lcd.filled_rectangle(70, 20, 127, 30, GREEN);
+                break;
+            }
+            case (22): {
+                lcd.filled_rectangle(0, 80, 90, 90, RED);
+                lcd.filled_rectangle(70, 30, 127, 40, GREEN);
+                break;
+            }
+            case (21): {
+                lcd.filled_rectangle(0, 90, 90, 100, RED);
+                lcd.filled_rectangle(70, 40, 127, 50, GREEN);
+                break;
+            }
+            case (20): {
+                lcd.filled_rectangle(0, 100, 90, 110, RED);
+                lcd.filled_rectangle(70, 50, 127, 60, GREEN);
+                if(a<8) {
+                    lcd.locate(3,8);
+                    lcd.printf("YOU LOSE!!!");
+                    exit(0);
+                }
+                break;
+            }
+            case (19): {
+                lcd.filled_rectangle(0, 110, 100, 120, RED);
+                lcd.filled_rectangle(70, 60, 127, 70, GREEN);
+                lcd.filled_rectangle(40,0 , 90,10 , WHITE);
+                break;
+            }
+            case (18): {
+                lcd.filled_rectangle(0, 120, 100, 130, RED);
+                lcd.filled_rectangle(70, 70, 127, 80, GREEN);
+                lcd.filled_rectangle(40,10 , 90,20 , WHITE);
+                break;
+            }
+            case (17): {
+                lcd.filled_rectangle(70, 80, 127, 90, GREEN);
+                lcd.filled_rectangle(40,20 , 90, 30, WHITE);
+                break;
+            }
+            case (16): {
+                lcd.filled_rectangle(70, 90, 127, 100, GREEN);
+                lcd.filled_rectangle(40,30 , 90, 40, WHITE);
+                break;
+            }
+            case (15): {
+                lcd.filled_rectangle(70, 100, 127, 110, GREEN);
+                lcd.filled_rectangle(40,40 , 90,50 , WHITE);
+                if(a>6) {
+                    lcd.locate(3,8);
+                    lcd.printf("YOU LOSE!!!");
+                    exit(0);
+                }
+                break;
+            }
+            case (14): {
+                lcd.filled_rectangle(70, 110, 127, 120, GREEN);
+                lcd.filled_rectangle(40,50 , 90, 60, WHITE);
+                break;
+            }
+            case (13): {
+                lcd.filled_rectangle(70, 120, 127, 130, GREEN);
+                lcd.filled_rectangle(40, 60 , 90, 70, WHITE);
+                lcd.filled_rectangle(0, 0 , 30, 10, YELLOW);
+                lcd.filled_rectangle(60, 0 , 127, 10, YELLOW);
+                break;
+            }
+            case (12): {
+                lcd.filled_rectangle(40, 70, 90, 80 , WHITE);
+                lcd.filled_rectangle(0, 10, 30, 20, YELLOW);
+                lcd.filled_rectangle(60, 10, 127, 20, YELLOW);
+                break;
+            }
+            case (11): {
+                lcd.filled_rectangle(40, 80, 90, 90 , WHITE);
+                lcd.filled_rectangle(0, 20 , 30, 30, YELLOW);
+                lcd.filled_rectangle(60, 20 , 127, 30, YELLOW);
+                break;
+            }
+            case (10): {
+                lcd.filled_rectangle(40, 90, 90, 100 , WHITE);
+                lcd.filled_rectangle(0, 30 , 30, 40, YELLOW);
+                lcd.filled_rectangle(60, 30 , 127, 40, YELLOW);
+                break;
+            }
+            case (9): {
+                lcd.filled_rectangle(40,100 , 90, 110, WHITE);
+                lcd.filled_rectangle(0, 40 , 30, 50, YELLOW);
+                lcd.filled_rectangle(60, 40 , 127, 50, YELLOW);
+                if(a>3 && a<8 ) {
+                    lcd.locate(3,8);
+                    lcd.printf("YOU LOSE!!!");
+                    exit(0);
+                }
+                break;
+            }
+            case (8): {
+                lcd.filled_rectangle(40,110 , 90, 120, WHITE);
+                lcd.filled_rectangle(0, 50 , 30, 60, YELLOW);
+                lcd.filled_rectangle(60, 50 , 127, 60, YELLOW);
+                break;
+            }
+            case (7): {
+                lcd.filled_rectangle(40,120 , 90, 130, WHITE);
+                lcd.filled_rectangle(0, 60 , 30, 70, YELLOW);
+                lcd.filled_rectangle(60, 60 , 127, 70, YELLOW);
+                break;
+            }
+            case (6): {
+                lcd.filled_rectangle(0, 70 , 30, 80, YELLOW);
+                lcd.filled_rectangle(60, 70 , 127, 80, YELLOW);
+                break;
+            }
+            case (5): {
+                lcd.filled_rectangle(0, 80 , 30, 90, YELLOW);
+                lcd.filled_rectangle(60, 80 , 127, 90, YELLOW);
+                break;
+            }
+            case (4): {
+                lcd.filled_rectangle(0, 90 , 30, 100, YELLOW);
+                lcd.filled_rectangle(60, 90 , 127, 100, YELLOW);
+                break;
+            }
+            case (3): {
+                lcd.filled_rectangle(0, 100 , 30, 110, YELLOW);
+                lcd.filled_rectangle(60, 100 , 127, 110, YELLOW);
+                if(a<4 || a>5 ) {
+                    lcd.locate(3,8);
+                    lcd.printf("YOU LOSE!!!");
+                    exit(0);
+                }
+                break;
+            }
+            case (2): {
+                lcd.filled_rectangle(0, 110 , 30, 120, YELLOW);
+                lcd.filled_rectangle(60, 110 , 127, 120, YELLOW);
+                break;
+            }
+            case (1): {
+                lcd.filled_rectangle(0, 120 , 30, 130, YELLOW);
+                lcd.filled_rectangle(60, 120 , 127, 130, YELLOW);
+                break;
+            }
+
+        }
+        stdio_mutex.unlock();
+    }
+}
+
+
+#endif
\ No newline at end of file
--- a/main.cpp	Tue Mar 10 03:04:14 2015 +0000
+++ b/main.cpp	Tue Mar 10 03:54:34 2015 +0000
@@ -1,294 +1,16 @@
-#include "mbed.h"
-#include "uLCD_4DGL.h"
-#include "math.h"
-#include "rtos.h"
-#include "wave_player.h"
-#include "SDFileSystem.h"
-#include "Speaker.h"
-#include <string>
-
-#define YELLOW              0xFFFF00
-#define ORANGE              0xffdd76
-#define MECYAN              0x009696
-
-AnalogIn steer(p17);
-AnalogIn force(p16);
-AnalogIn timer(p20);
-uLCD_4DGL lcd(p28, p27, p30);
-Mutex stdio_mutex;
-
-volatile int count=30;
-volatile int a=0;
-volatile int cheat=3;
-
-void forward(void const *args)
-{
-    while(1) {
-        if (timer<0.1) {
-            if(count<29 && cheat>0) {
-                ++count;
-                ++count;
-                --cheat;
-            }
-        }
-        Thread::wait(400);
-    }
-}
-
-void steering(void const *args)
-{
-    while(1) {
-        stdio_mutex.lock();
-        lcd.cls();
-        a=floor(steer*39);
-        if(a>9) {
-            a=9;
-        }
-        switch(a) {
-            case (1): {
-                lcd.filled_rectangle(0, 98, 9, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (2): {
-                lcd.filled_rectangle(14, 98, 23, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (3): {
-                lcd.filled_rectangle(28, 98, 37, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (4): {
-                lcd.filled_rectangle(42, 98, 51, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (5): {
-                lcd.filled_rectangle(56, 98, 65, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (6): {
-                lcd.filled_rectangle(70, 98, 79, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (7): {
-                lcd.filled_rectangle(84, 98, 93, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (8): {
-                lcd.filled_rectangle(98, 98, 107, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-            case (9): {
-                lcd.filled_rectangle(112, 98, 121, 110, BLUE);
-                Thread::wait(200);
-                break;
-            }
-        }
-        stdio_mutex.unlock();
-    }
-}
+#include "head.h"
 
-void obstacle(void const *args)
-{
-    while(1) {
-        stdio_mutex.lock();
-        switch(count) {
-            case (30): {
-                lcd.filled_rectangle(0, 0, 90, 10, RED);
-                break;
-            }
-            case (29): {
-                lcd.filled_rectangle(0, 10, 90, 20, RED);
-                break;
-            }
-            case (28): {
-                lcd.filled_rectangle(0, 20, 90, 30, RED);
-                break;
-            }
-            case (27): {
-                lcd.filled_rectangle(0, 30, 90, 40, RED);
-                break;
-            }
-            case (26): {
-                lcd.filled_rectangle(0, 40, 90, 50, RED);
-                break;
-            }
-            case (25): {
-                lcd.filled_rectangle(0, 50, 90, 60, RED);
-                lcd.filled_rectangle(70, 0, 90, 10, GREEN);
-                break;
-            }
-            case (24): {
-                lcd.filled_rectangle(0, 60, 90, 70, RED);
-                lcd.filled_rectangle(70, 10, 127, 20, GREEN);
-                break;
-            }
-            case (23): {
-                lcd.filled_rectangle(0, 70, 90, 80, RED);
-                lcd.filled_rectangle(70, 20, 127, 30, GREEN);
-                break;
-            }
-            case (22): {
-                lcd.filled_rectangle(0, 80, 90, 90, RED);
-                lcd.filled_rectangle(70, 30, 127, 40, GREEN);
-                break;
-            }
-            case (21): {
-                lcd.filled_rectangle(0, 90, 90, 100, RED);
-                lcd.filled_rectangle(70, 40, 127, 50, GREEN);
-                break;
-            }
-            case (20): {
-                lcd.filled_rectangle(0, 100, 90, 110, RED);
-                lcd.filled_rectangle(70, 50, 127, 60, GREEN);
-                if(a<8) {
-                    lcd.locate(3,8);
-                    lcd.printf("YOU LOSE!!!");
-                    exit(0);
-                }
-                break;
-            }
-            case (19): {
-                lcd.filled_rectangle(0, 110, 100, 120, RED);
-                lcd.filled_rectangle(70, 60, 127, 70, GREEN);
-                lcd.filled_rectangle(40,0 , 90,10 , WHITE);
-                break;
-            }
-            case (18): {
-                lcd.filled_rectangle(0, 120, 100, 130, RED);
-                lcd.filled_rectangle(70, 70, 127, 80, GREEN);
-                lcd.filled_rectangle(40,10 , 90,20 , WHITE);
-                break;
-            }
-            case (17): {
-                lcd.filled_rectangle(70, 80, 127, 90, GREEN);
-                lcd.filled_rectangle(40,20 , 90, 30, WHITE);
-                break;
-            }
-            case (16): {
-                lcd.filled_rectangle(70, 90, 127, 100, GREEN);
-                lcd.filled_rectangle(40,30 , 90, 40, WHITE);
-                break;
-            }
-            case (15): {
-                lcd.filled_rectangle(70, 100, 127, 110, GREEN);
-                lcd.filled_rectangle(40,40 , 90,50 , WHITE);
-                if(a>6) {
-                    lcd.locate(3,8);
-                    lcd.printf("YOU LOSE!!!");
-                    exit(0);
-                }
-                break;
-            }
-            case (14): {
-                lcd.filled_rectangle(70, 110, 127, 120, GREEN);
-                lcd.filled_rectangle(40,50 , 90, 60, WHITE);
-                break;
-            }
-            case (13): {
-                lcd.filled_rectangle(70, 120, 127, 130, GREEN);
-                lcd.filled_rectangle(40, 60 , 90, 70, WHITE);
-                lcd.filled_rectangle(0, 0 , 30, 10, YELLOW);
-                lcd.filled_rectangle(60, 0 , 127, 10, YELLOW);
-                break;
-            }
-            case (12): {
-                lcd.filled_rectangle(40, 70, 90, 80 , WHITE);
-                lcd.filled_rectangle(0, 10, 30, 20, YELLOW);
-                lcd.filled_rectangle(60, 10, 127, 20, YELLOW);
-                break;
-            }
-            case (11): {
-                lcd.filled_rectangle(40, 80, 90, 90 , WHITE);
-                lcd.filled_rectangle(0, 20 , 30, 30, YELLOW);
-                lcd.filled_rectangle(60, 20 , 127, 30, YELLOW);
-                break;
-            }
-            case (10): {
-                lcd.filled_rectangle(40, 90, 90, 100 , WHITE);
-                lcd.filled_rectangle(0, 30 , 30, 40, YELLOW);
-                lcd.filled_rectangle(60, 30 , 127, 40, YELLOW);
-                break;
-            }
-            case (9): {
-                lcd.filled_rectangle(40,100 , 90, 110, WHITE);
-                lcd.filled_rectangle(0, 40 , 30, 50, YELLOW);
-                lcd.filled_rectangle(60, 40 , 127, 50, YELLOW);
-                if(a>3 && a<8 ) {
-                    lcd.locate(3,8);
-                    lcd.printf("YOU LOSE!!!");
-                    exit(0);
-                }
-                break;
-            }
-            case (8): {
-                lcd.filled_rectangle(40,110 , 90, 120, WHITE);
-                lcd.filled_rectangle(0, 50 , 30, 60, YELLOW);
-                lcd.filled_rectangle(60, 50 , 127, 60, YELLOW);
-                break;
-            }
-            case (7): {
-                lcd.filled_rectangle(40,120 , 90, 130, WHITE);
-                lcd.filled_rectangle(0, 60 , 30, 70, YELLOW);
-                lcd.filled_rectangle(60, 60 , 127, 70, YELLOW);
-                break;
-            }
-            case (6): {
-                lcd.filled_rectangle(0, 70 , 30, 80, YELLOW);
-                lcd.filled_rectangle(60, 70 , 127, 80, YELLOW);
-                break;
-            }
-            case (5): {
-                lcd.filled_rectangle(0, 80 , 30, 90, YELLOW);
-                lcd.filled_rectangle(60, 80 , 127, 90, YELLOW);
-                break;
-            }
-            case (4): {
-                lcd.filled_rectangle(0, 90 , 30, 100, YELLOW);
-                lcd.filled_rectangle(60, 90 , 127, 100, YELLOW);
-                break;
-            }
-            case (3): {
-                lcd.filled_rectangle(0, 100 , 30, 110, YELLOW);
-                lcd.filled_rectangle(60, 100 , 127, 110, YELLOW);
-                if(a<4 || a>5 ) {
-                    lcd.locate(3,8);
-                    lcd.printf("YOU LOSE!!!");
-                    exit(0);
-                }
-                break;
-            }
-            case (2): {
-                lcd.filled_rectangle(0, 110 , 30, 120, YELLOW);
-                lcd.filled_rectangle(60, 110 , 127, 120, YELLOW);
-                break;
-            }
-            case (1): {
-                lcd.filled_rectangle(0, 120 , 30, 130, YELLOW);
-                lcd.filled_rectangle(60, 120 , 127, 130, YELLOW);
-                break;
-            }
+void start();
+void forward(void const *args);
+void steering(void const *args);
+void obstacle(void const *args);
 
-        }
-        stdio_mutex.unlock();
-    }
-}
+
 
+    
 int main(void)
 {
-    lcd.printf("Need for Speed  :P  \n");
-    lcd.printf("------------------");
-    lcd.printf("1. Rotation Sensor - To steer right or left\n\n");
-    lcd.printf("2. Force Sensor - To speed up\n\n");
-    lcd.printf("3. Touch Sensor - To Cheat (3 times max)\n\n\n");
-    lcd.printf("  Touch to begin!\n");
+    start();
     
     while(timer);
     
--- a/wave_player/wave_player.cpp	Tue Mar 10 03:04:14 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,226 +0,0 @@
-//-----------------------------------------------------------------------------
-// a sample mbed library to play back wave files.
-//
-// explanation of wave file format.
-// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
-
-// if VERBOSE is uncommented then the wave player will enter a verbose
-// mode that displays all data values as it reads them from the file
-// and writes them to the DAC.  Very slow and unusable output on the DAC,
-// but useful for debugging wave files that don't work.
-//#define VERBOSE
-
-
-#include <mbed.h>
-#include <stdio.h>
-#include <wave_player.h>
-
-void wave_player::setStop(bool logic)
-{
-    stop = logic;
-}
-bool wave_player::isStop()
-{
-    return stop;
-}
-//-----------------------------------------------------------------------------
-// constructor -- accepts an mbed pin to use for AnalogOut.  Only p18 will work
-wave_player::wave_player(AnalogOut *_dac)
-{
-  wave_DAC=_dac;
-  wave_DAC->write_u16(32768);        //DAC is 0-3.3V, so idles at ~1.6V
-  verbosity=0;
-}
-int * wave_player:: getVolume() 
-{
-        return & volume;
-    }
-
-//-----------------------------------------------------------------------------
-// if verbosity is set then wave player enters a mode where the wave file
-// is decoded and displayed to the screen, including sample values put into
-// the DAC FIFO, and values read out of the DAC FIFO by the ISR.  The DAC output
-// itself is so slow as to be unusable, but this might be handy for debugging
-// wave files that don't play
-//-----------------------------------------------------------------------------
-void wave_player::set_verbosity(int v)
-{
-  verbosity=v;
-}
-
-//-----------------------------------------------------------------------------
-// player function.  Takes a pointer to an opened wave file.  The file needs
-// to be stored in a filesystem with enough bandwidth to feed the wave data.
-// LocalFileSystem isn't, but the SDcard is, at least for 22kHz files.  The
-// SDcard filesystem can be hotrodded by increasing the SPI frequency it uses
-// internally.
-//-----------------------------------------------------------------------------
-void wave_player::play(FILE *wavefile)
-{
-        unsigned chunk_id,chunk_size,channel;
-        unsigned data,samp_int,i;
-        short unsigned dac_data;
-        long long slice_value;
-        char *slice_buf;
-        short *data_sptr;
-        unsigned char *data_bptr;
-        int *data_wptr;
-        FMT_STRUCT wav_format;
-        long slice,num_slices;
-  DAC_wptr=0;
-  DAC_rptr=0;
-  for (i=0;i<256;i+=2) {
-    DAC_fifo[i]=0;
-    DAC_fifo[i+1]=3000;
-  }
-  DAC_wptr=4;
-  DAC_on=0;
-
-  fread(&chunk_id,4,1,wavefile);
-  fread(&chunk_size,4,1,wavefile);
-  while (!feof(wavefile) && (isStop() == false) ) {
-    if (verbosity)
-      printf("Read chunk ID 0x%x, size 0x%x\n",chunk_id,chunk_size);
-    switch (chunk_id) {
-      case 0x46464952:
-        fread(&data,4,1,wavefile);
-        if (verbosity) {
-          printf("RIFF chunk\n");
-          printf("  chunk size %d (0x%x)\n",chunk_size,chunk_size);
-          printf("  RIFF type 0x%x\n",data);
-        }
-        break;
-      case 0x20746d66:
-        fread(&wav_format,sizeof(wav_format),1,wavefile);
-        if (verbosity) {
-          printf("FORMAT chunk\n");
-          printf("  chunk size %d (0x%x)\n",chunk_size,chunk_size);
-          printf("  compression code %d\n",wav_format.comp_code);
-          printf("  %d channels\n",wav_format.num_channels);
-          printf("  %d samples/sec\n",wav_format.sample_rate);
-          printf("  %d bytes/sec\n",wav_format.avg_Bps);
-          printf("  block align %d\n",wav_format.block_align);
-          printf("  %d bits per sample\n",wav_format.sig_bps);
-        }
-        if (chunk_size > sizeof(wav_format))
-          fseek(wavefile,chunk_size-sizeof(wav_format),SEEK_CUR);
-        break;
-      case 0x61746164:
-// allocate a buffer big enough to hold a slice
-        slice_buf=(char *)malloc(wav_format.block_align);
-        if (!slice_buf) {
-          printf("Unable to malloc slice buffer");
-          exit(1);
-        }
-        num_slices=chunk_size/wav_format.block_align;
-        samp_int=1000000/(wav_format.sample_rate);
-        if (verbosity) {
-          printf("DATA chunk\n");
-          printf("  chunk size %d (0x%x)\n",chunk_size,chunk_size);
-          printf("  %d slices\n",num_slices);
-          printf("  Ideal sample interval=%d\n",(unsigned)(1000000.0/wav_format.sample_rate));
-          printf("  programmed interrupt tick interval=%d\n",samp_int);
-        }
-
-// starting up ticker to write samples out -- no printfs until tick.detach is called
-        if (verbosity)
-          tick.attach_us(this,&wave_player::dac_out, 500000); 
-        else
-          tick.attach_us(this,&wave_player::dac_out, samp_int); 
-        DAC_on=1; 
-
-// start reading slices, which contain one sample each for however many channels
-// are in the wave file.  one channel=mono, two channels=stereo, etc.  Since
-// mbed only has a single AnalogOut, all of the channels present are averaged
-// to produce a single sample value.  This summing and averaging happens in
-// a variable of type signed long long, to make sure that the data doesn't
-// overflow regardless of sample size (8 bits, 16 bits, 32 bits).
-//
-// note that from what I can find that 8 bit wave files use unsigned data,
-// while 16 and 32 bit wave files use signed data
-//
-        for (slice=0;slice<num_slices;slice+=1) {
-          fread(slice_buf,wav_format.block_align,1,wavefile);
-          if (feof(wavefile)) {
-            printf("Oops -- not enough slices in the wave file\n");
-            exit(1);
-          }
-          if (isStop() == true)//stop the song
-          {
-              break;
-          }
-          data_sptr=(short *)slice_buf;     // 16 bit samples
-          data_bptr=(unsigned char *)slice_buf;     // 8 bit samples
-          data_wptr=(int *)slice_buf;     // 32 bit samples
-          slice_value=0;
-          for (channel=0;channel<wav_format.num_channels;channel++) {
-            switch (wav_format.sig_bps) {
-              case 16:
-                if (verbosity)
-                  printf("16 bit channel %d data=%d ",channel,data_sptr[channel]);
-                slice_value+=data_sptr[channel];
-                break;
-              case 32:
-                if (verbosity)
-                  printf("32 bit channel %d data=%d ",channel,data_wptr[channel]);
-                slice_value+=data_wptr[channel];
-                break;
-              case 8:
-                if (verbosity)
-                  printf("8 bit channel %d data=%d ",channel,(int)data_bptr[channel]);
-                slice_value+=data_bptr[channel];
-                break;
-            }
-          }
-          slice_value/=wav_format.num_channels;
-          
-// slice_value is now averaged.  Next it needs to be scaled to an unsigned 16 bit value
-// with DC offset so it can be written to the DAC.
-          switch (wav_format.sig_bps) {
-            case 8:     slice_value<<=8;
-                        break;
-            case 16:    slice_value+=32768;
-                        break;
-            case 32:    slice_value>>=16;
-                        slice_value+=32768;
-                        break;
-          }
-          dac_data=(short unsigned)slice_value;
-          if (verbosity)
-            printf("sample %d wptr %d slice_value %d dac_data %u\n",slice,DAC_wptr,(int)slice_value,dac_data);
-          DAC_fifo[DAC_wptr]=dac_data;
-          DAC_wptr=(DAC_wptr+1) & 0xff;
-          while (DAC_wptr==DAC_rptr) {
-          }
-        }
-        DAC_on=0;
-        tick.detach();
-        free(slice_buf);
-        break;
-      case 0x5453494c:
-        if (verbosity)
-          printf("INFO chunk, size %d\n",chunk_size);
-        fseek(wavefile,chunk_size,SEEK_CUR);
-        break;
-      default:
-        printf("unknown chunk type 0x%x, size %d\n",chunk_id,chunk_size);
-        data=fseek(wavefile,chunk_size,SEEK_CUR);
-        break;
-    }
-    fread(&chunk_id,4,1,wavefile);
-    fread(&chunk_size,4,1,wavefile);
-  }
-}
-
-
-void wave_player::dac_out()
-{
-  if (DAC_on) {
-#ifdef VERBOSE
-  printf("ISR rdptr %d got %u\n",DAC_rptr,DAC_fifo[DAC_rptr]);
-#endif
-  //  DAC_fifo[DAC_wptr]=((16-*vol)* dac_data)>>4;
-    wave_DAC->write_u16((DAC_fifo[DAC_rptr] * (16 - volume))>>4);
-    DAC_rptr=(DAC_rptr+1) & 0xff;
-  }
-}
--- a/wave_player/wave_player.h	Tue Mar 10 03:04:14 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-#include <mbed.h>
-
-typedef struct uFMT_STRUCT {
-  short comp_code;
-  short num_channels;
-  unsigned sample_rate;
-  unsigned avg_Bps;
-  short block_align;
-  short sig_bps;
-} FMT_STRUCT;
-
-
-/** wave file player class.
- *
- * Example:
- * @code
- * #include <mbed.h>
- * #include <wave_player.h>
- *
- * AnalogOut DACout(p18);
- * wave_player waver(&DACout);
- *
- * int main() {
- *  FILE *wave_file;
- *  
- *  printf("\n\n\nHello, wave world!\n");
- *  wave_file=fopen("/sd/44_8_st.wav","r");
- *  waver.play(wave_file);
- *  fclose(wave_file); 
- * }
- * @endcode
- */
-class wave_player {
-
-public:
-/** Create a wave player using a pointer to the given AnalogOut object.
- *
- * @param _dac pointer to an AnalogOut object to which the samples are sent.
- */
-wave_player(AnalogOut *_dac);
-/** the player function.
- *
- * @param wavefile  A pointer to an opened wave file
- */
-void play(FILE *wavefile);
-void setStop(bool);//set stop condition
-bool isStop(); //get stop condition
-int * getVolume(void); // get Volume function 
-
-
-/** Set the printf verbosity of the wave player.  A nonzero verbosity level
- * will put wave_player in a mode where the complete contents of the wave
- * file are echoed to the screen, including header values, and including
- * all of the sample values placed into the DAC FIFO, and the sample values
- * removed from the DAC FIFO by the ISR.  The sample output frequency is
- * fixed at 2 Hz in this mode, so it's all very slow and the DAC output isn't
- * very useful, but it lets you see what's going on and may help for debugging
- * wave files that don't play correctly.
- *
- * @param v the verbosity level
- */
-void set_verbosity(int v);
-
-private:
-int volume;
-void dac_out(void);
-bool stop; 
-int verbosity;
-AnalogOut *wave_DAC;
-Ticker tick;
-unsigned short DAC_fifo[256];
-short DAC_wptr;
-volatile short DAC_rptr;
-short DAC_on;
-};
-