Advertisement
weaknetlabs

BlizzyB Ocean Edition Firmware v0.5

Oct 14th, 2014
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.41 KB | None | 0 0
  1. /*
  2.   BlizzyB Sine Ed. - Douglas Berdeaux 2014 (C) GNU
  3.   Firmware version 0.2 (Still in BETA)
  4.   This project requires a lot of knowledge about SD card reading and the TMRpcm library.
  5.   Please see WeakNetLabs.com for more details.
  6. */
  7. #include <SD.h> // preprocessor directives (header files)
  8. #define SDPIN 10    // SD Card Pin for SeeedStudio SD Card Shield
  9. #include <TMRpcm.h> // to play WAV files
  10. #include <Keypad.h> // for the keypad
  11. char sound[20] = "sounds/blusinxx.wav";
  12. int b2600 = 15; // 2600Hz Supervisory Signalling button
  13. File myFile; // create objects here from library classes
  14. TMRpcm tmrpcm; // create sound playing object
  15. char keys[4][4] = { // matrix layout used by the Keypad library
  16.   {'1','2','3','a'},
  17.   {'4','5','6','b'},
  18.   {'7','8','9','c'},
  19.   {'*','0','#','d'}
  20. };
  21. int store[24] = { // this is where we will store our digits
  22.   -1,-1,-1,-1,-1,-1,-1,-1,
  23.   -1,-1,-1,-1,-1,-1,-1,-1
  24. };
  25. byte rowPins[4] = {5,4,3,2}; //connect to the row pinouts of the keypad
  26. byte colPins[4] = {14,8,7,6}; //connect to the column pinouts of the keypad
  27. Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
  28. boolean rec = false; // recording boolean
  29. boolean stored = false; // stored digits? not at startup!
  30.  
  31. void setup(){
  32.   Serial.begin(9600);
  33.   pinMode(b2600, INPUT); // A1 2600 button
  34.   keypad.addEventListener(procButton); // listener for buttons pressed/held/released
  35.   keypad.setHoldTime(1500); // hold for two seconds to change state to HOLD
  36.   if (!SD.begin(SDPIN)) {
  37.     Serial.println("initialization failed!");
  38.   }else{
  39.     Serial.println("initialization success!");
  40.   }
  41.   tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc
  42.   tmrpcm.setVolume(3); // set volume here (test for distortion)
  43.   file("bu",1000);
  44.   return;
  45. }
  46.  
  47. void loop(){
  48.   if(digitalRead(b2600)==HIGH){ // play 2600Hz if button pressed
  49.     file("26",1000); // supervisory signalling
  50.   }
  51.   char button = keypad.getKey(); // check for button press
  52.   return;
  53. }
  54.  
  55. void file(char a[2],int i){ // file name (save memory)
  56.   sound[13] = a[0];
  57.   sound[14] = a[1];
  58.   tmrpcm.play(sound);
  59.   delay (i);
  60.   return;
  61. }
  62.  
  63. void procButton(KeypadEvent b){
  64.   int intB = b - 48;
  65.   switch(keypad.getState()){ // if a button was pressed
  66.     case RELEASED:
  67.       return;
  68.     case PRESSED: // pressed a button
  69.       if(rec && (intB==-13||intB==-6||(intB>=0&&intB<=9))){ // store it, right off the bat
  70.         storeDigit(intB);
  71.       }
  72.       if(intB>-1&&intB<10){ // 0-9
  73.         char c[2];
  74.         c[0] = '0';
  75.         c[1] = b; // keypadevent object same as char
  76.         file(c,100);
  77.       }else if(intB==-6){ // KP
  78.         file("kp",200);
  79.       }else if(intB==-13){ // ST
  80.         file("st",200);
  81.       }else if(stored&&intB==52){
  82.         playBack();
  83.        return;
  84.       }
  85.       break;
  86.     case HOLD:
  87.       if(intB==51){ // HELD C
  88.         if(rec){ // we are done recording:
  89.           rec = false;
  90.           if(store[0] != -1){ // if nothing was stored, set to true:
  91.             stored = true; // we have digits stored
  92.           }else{
  93.             stored = false; // fuckem
  94.           }
  95.         }else{ // we start recording
  96.           rec = true;
  97.           resetStore();
  98.         }
  99.         recNotify();
  100.         break;
  101.       }else if(intB==49){
  102.         file("h0",1000);
  103.         break;
  104.       }
  105.   }
  106.   return;
  107. }
  108.  
  109. void resetStore(void){
  110.   for(int i=0;i<=16;i++){
  111.     store[i] = -1;
  112.   }
  113.   return;
  114. }
  115.  
  116. void storeDigit(int digit){
  117.   for(int i=0;i<=15;i++){
  118.     if(store[i]==-1){
  119.       store[i] = digit;
  120.       return;
  121.     }
  122.   }
  123.   return;
  124. }
  125.  
  126. void playBack(void){
  127.   for(int i=0;i<=15;i++){
  128.     char c[2];
  129.     if(store[i] != -1){ // we have a digit
  130.       if(store[i] >=0){ // 0-9
  131.         c[0] = '0';
  132.         char b[2];
  133.         String str;
  134.         str=String(store[i]);
  135.         str.toCharArray(b,2);
  136.         c[1] = b[0];
  137.       }else{ // kp && st
  138.         if(store[i]==-6){
  139.           c[0] = 'k';
  140.           c[1] = 'p';
  141.         }else if(store[i]==-13){
  142.           c[0] = 's';
  143.           c[1] = 't';
  144.         }
  145.       }
  146.       file(c,100); // 66ms on + 34 silence
  147.       delay(32);   // + 32 more silence
  148.     }else{
  149.       return; // hit a -1
  150.     }
  151.   }
  152.   return;
  153. }
  154.  
  155. void recNotify(void){
  156.  if(rec){  // we are recording:
  157.    file("r0",100);
  158.  }else if(!rec&&stored){ // we have recorded data
  159.    file("r1",100);
  160.  }else{ // we are done rcording, but nothing stored
  161.    file("r2",100);
  162.  }
  163.  return;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement