A Proof of Concept of a simple sound module.

The design criteria of the module was

  1. Light weight Arduino hardware
  2. Sound files stored on a micro SD Card
  3. Input (throttle) read from RC receiver
  4. Fixed (in the example below four) number of sound files for different levels of throttle



Arduino Program based on the TMRPcm.lib

    1:
    2: #include <SD.h>                      // need to include the SD library
    3: #define SD_ChipSelectPin 10  //using digital pin 4 on arduino nano 328, can use other pins
    4: #include <TMRpcm.h>           //  also need to include this library...
    5: #include <SPI.h>
    6:
    7: TMRpcm tmrpcm;   // create an object for use in this sketch
    8:
    9: unsigned long time = 0;
   10: int numLoop = 0;
   11: int throttle = 0;
   12: int prevThrottle = 0;
   13: int currThrottle = 0;
   14:
   15: //RC scale
   16: int rc_pin = 2;
   17: unsigned long duration;
   18:
   19: void setup(){
   20:   tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
   21:   Serial.begin(115200);
   22:   if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
   23:     Serial.println("SD fail");  
   24:     return;   // don't do anything more if not
   25:   }
   26:   else{  
   27:     Serial.println("SD ok");  
   28:   }
   29:   //PLay init file to tell sound version
   30:   tmrpcm.play("init.wav");
   31:   while(tmrpcm.isPlaying()){};
   32: }
   33:
   34: void loop(){  
   35:
   36:   //Read throttel value
   37:   ++numLoop;
   38:   if (numLoop == 30000){
   39:       noInterrupts();
   40:       duration = pulseIn(rc_pin, HIGH);
   41:       interrupts();
   42:       numLoop = 0;
   43:       throttle = (duration - 700) / 16;
   44:  
   45:     //Set new throttle value
   46:     if(throttle <= 25){
   47:       currThrottle = 1;
   48:     };
   49:     if((throttle >= 25) && (throttle <= 50)){
   50:       currThrottle = 2;
   51:     };
   52:     if((throttle >= 50) && (throttle <= 75)){
   53:       currThrottle = 3;
   54:     };
   55:     if(throttle >= 75){
   56:       currThrottle = 4;
   57:     };
   58:  
   59:     //If currThrottle != prevThrottle set start playing new file
   60:     if(currThrottle != prevThrottle){
   61:       if(currThrottle == 1){
   62:         tmrpcm.play("idle.wav");
   63:         Serial.println("tmrpcm.play(idle.wav);");
   64:         prevThrottle = currThrottle;
   65:       }
   66:       if(currThrottle == 2){
   67:         tmrpcm.play("mid-low.wav");
   68:         Serial.println("tmrpcm.play(mid-low.wav);");
   69:         prevThrottle = currThrottle;
   70:       }
   71:       if(currThrottle == 3){
   72:         tmrpcm.play("mid-high.wav");
   73:         Serial.println("tmrpcm.play(mid-high.wav);");
   74:         prevThrottle = currThrottle;
   75:       }
   76:       if(currThrottle == 4){
   77:         tmrpcm.play("full.wav");
   78:         Serial.println("tmrpcm.play(full.wav);");
   79:         prevThrottle = currThrottle;
   80:       }
   81:     }
   82:   }
   83: }