daily pastebin goal
33%
SHARE
TWEET

BlizzyB Ocean Edition Firmware v0.5

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