Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- BlizzyB Sine Ed. - Douglas Berdeaux 2014 (C) GNU
- Firmware version 0.2 (Still in BETA)
- This project requires a lot of knowledge about SD card reading and the TMRpcm library.
- Please see WeakNetLabs.com for more details.
- */
- #include <SD.h> // preprocessor directives (header files)
- #define SDPIN 10 // SD Card Pin for SeeedStudio SD Card Shield
- #include <TMRpcm.h> // to play WAV files
- #include <Keypad.h> // for the keypad
- char sound[20] = "sounds/blusinxx.wav";
- int b2600 = 15; // 2600Hz Supervisory Signalling button
- File myFile; // create objects here from library classes
- TMRpcm tmrpcm; // create sound playing object
- char keys[4][4] = { // matrix layout used by the Keypad library
- {'1','2','3','a'},
- {'4','5','6','b'},
- {'7','8','9','c'},
- {'*','0','#','d'}
- };
- int store[24] = { // this is where we will store our digits
- -1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1
- };
- byte rowPins[4] = {5,4,3,2}; //connect to the row pinouts of the keypad
- byte colPins[4] = {14,8,7,6}; //connect to the column pinouts of the keypad
- Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
- boolean rec = false; // recording boolean
- boolean stored = false; // stored digits? not at startup!
- void setup(){
- Serial.begin(9600);
- pinMode(b2600, INPUT); // A1 2600 button
- keypad.addEventListener(procButton); // listener for buttons pressed/held/released
- keypad.setHoldTime(1500); // hold for two seconds to change state to HOLD
- if (!SD.begin(SDPIN)) {
- Serial.println("initialization failed!");
- }else{
- Serial.println("initialization success!");
- }
- tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc
- tmrpcm.setVolume(3); // set volume here (test for distortion)
- file("bu",1000);
- return;
- }
- void loop(){
- if(digitalRead(b2600)==HIGH){ // play 2600Hz if button pressed
- file("26",1000); // supervisory signalling
- }
- char button = keypad.getKey(); // check for button press
- return;
- }
- void file(char a[2],int i){ // file name (save memory)
- sound[13] = a[0];
- sound[14] = a[1];
- tmrpcm.play(sound);
- delay (i);
- return;
- }
- void procButton(KeypadEvent b){
- int intB = b - 48;
- switch(keypad.getState()){ // if a button was pressed
- case RELEASED:
- return;
- case PRESSED: // pressed a button
- if(rec && (intB==-13||intB==-6||(intB>=0&&intB<=9))){ // store it, right off the bat
- storeDigit(intB);
- }
- if(intB>-1&&intB<10){ // 0-9
- char c[2];
- c[0] = '0';
- c[1] = b; // keypadevent object same as char
- file(c,100);
- }else if(intB==-6){ // KP
- file("kp",200);
- }else if(intB==-13){ // ST
- file("st",200);
- }else if(stored&&intB==52){
- playBack();
- return;
- }
- break;
- case HOLD:
- if(intB==51){ // HELD C
- if(rec){ // we are done recording:
- rec = false;
- if(store[0] != -1){ // if nothing was stored, set to true:
- stored = true; // we have digits stored
- }else{
- stored = false; // fuckem
- }
- }else{ // we start recording
- rec = true;
- resetStore();
- }
- recNotify();
- break;
- }else if(intB==49){
- file("h0",1000);
- break;
- }
- }
- return;
- }
- void resetStore(void){
- for(int i=0;i<=16;i++){
- store[i] = -1;
- }
- return;
- }
- void storeDigit(int digit){
- for(int i=0;i<=15;i++){
- if(store[i]==-1){
- store[i] = digit;
- return;
- }
- }
- return;
- }
- void playBack(void){
- for(int i=0;i<=15;i++){
- char c[2];
- if(store[i] != -1){ // we have a digit
- if(store[i] >=0){ // 0-9
- c[0] = '0';
- char b[2];
- String str;
- str=String(store[i]);
- str.toCharArray(b,2);
- c[1] = b[0];
- }else{ // kp && st
- if(store[i]==-6){
- c[0] = 'k';
- c[1] = 'p';
- }else if(store[i]==-13){
- c[0] = 's';
- c[1] = 't';
- }
- }
- file(c,100); // 66ms on + 34 silence
- delay(32); // + 32 more silence
- }else{
- return; // hit a -1
- }
- }
- return;
- }
- void recNotify(void){
- if(rec){ // we are recording:
- file("r0",100);
- }else if(!rec&&stored){ // we have recorded data
- file("r1",100);
- }else{ // we are done rcording, but nothing stored
- file("r2",100);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement