Advertisement
Badjer1983

Arduino NFL Sound Bite Machine

Dec 6th, 2017
153
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //TMRpcm library is needed
  2.  
  3. #include "SD.h"
  4. #define SD_ChipSelectPin 10
  5. #include "TMRpcm.h"
  6. #include "SPI.h"
  7.  
  8. TMRpcm tmrpcm;
  9. const int buttonPin = 2;    
  10. const int ledPin =  4;    
  11. int ledState = LOW;
  12. boolean buttonState = LOW;
  13.  
  14. int pressed=0;
  15.  
  16. void setup() {
  17.   pinMode(ledPin, OUTPUT);
  18.   pinMode(buttonPin, INPUT);
  19. tmrpcm.speakerPin=9;
  20. Serial.begin(9600);
  21. if(!SD.begin(SD_ChipSelectPin))
  22. {
  23.   Serial.println("SD fail");
  24.   return;
  25. }
  26. tmrpcm.setVolume(5);
  27. }
  28.  
  29. void loop() {
  30.  
  31.   if(debounceButton(buttonState) == HIGH && buttonState == LOW)
  32.   {
  33.     pressed++;
  34.     buttonState = HIGH;
  35.  
  36.     switch (pressed){
  37.       case 1:
  38.         tmrpcm.play("1.wav");
  39.         break;
  40.       case 2:
  41.         tmrpcm.play("2.wav");
  42.         break;
  43.       case 3:
  44.         tmrpcm.play("3.wav");
  45.         break;
  46.       case 4:
  47.         tmrpcm.play("4.wav");
  48.         break;
  49.       case 5:
  50.         tmrpcm.play("5.wav");
  51.         break;
  52.       case 6:
  53.         tmrpcm.play("6.wav");
  54.         break;
  55.       case 7:
  56.         tmrpcm.play("7.wav");
  57.         break;
  58.       case 8:
  59.         tmrpcm.play("8.wav");      
  60.         break;
  61.       case 9:
  62.         tmrpcm.play("9.wav");
  63.         break;
  64.       case 10:
  65.         tmrpcm.play("10.wav");
  66.         break;
  67.       case 11:
  68.         tmrpcm.play("11.wav");
  69.         break;
  70.       case 12:
  71.         tmrpcm.play("12.wav");
  72.         break;
  73.       case 13:
  74.         tmrpcm.play("13.wav");
  75.         break;
  76.       default:
  77.         pressed = 0;
  78.      }
  79.  //...............................
  80.   }
  81.   else if(debounceButton(buttonState) == LOW && buttonState == HIGH)
  82.   {
  83.        buttonState = LOW;
  84.  
  85.          }
  86.   }
  87.  
  88. boolean debounceButton(boolean state)
  89. {
  90.   boolean stateNow = digitalRead(buttonPin);
  91.   if(state!=stateNow)
  92.   {
  93.     delay(10);
  94.     stateNow = digitalRead(buttonPin);
  95.   }
  96.   return stateNow;
  97. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement