Advertisement
Guest User

Mitch Music Code

a guest
May 24th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. // CODE FOR MITCH
  2.  
  3. #include <SimpleSDAudio.h>
  4.  
  5. // constants won't change. They're used here to
  6. // set pin numbers:
  7. const int buttonPin = 2; // the number of the pushbutton pin
  8. const int ledPin = 13; // the number of the LED pin
  9.  
  10. // variables will change:
  11. int buttonState = 0; // variable for reading the pushbutton status
  12.  
  13.  
  14.  
  15.  
  16. void setup()
  17. {
  18. // Open serial communications and wait for port to open:
  19. Serial.begin(9600);
  20.  
  21. int sensorValue = analogRead(A0);
  22.  
  23. while (!Serial) {
  24. ; // wait for serial port to connect. Needed for Leonardo only
  25.  
  26. // initialize the LED pin as an output:
  27. pinMode(ledPin, OUTPUT);
  28. // initialize the pushbutton pin as an input:
  29. pinMode(buttonPin, INPUT);
  30. }
  31.  
  32. // Using F("...") to avoid wasting RAM
  33. Serial.print(F("\nInitializing SD card..."));
  34.  
  35. // If your SD card CS-Pin is not at Pin 4, enable and adapt the following line:
  36. // SdPlay.setSDCSPin(10);
  37.  
  38. if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER)) {
  39. Serial.println(F("initialization failed. Things to check:"));
  40. Serial.println(F("* is a card is inserted?"));
  41. Serial.println(F("* Is your wiring correct?"));
  42. Serial.println(F("* maybe you need to change the chipSelect pin to match your shield or module?"));
  43. Serial.print(F("Error code: "));
  44. Serial.println(SdPlay.getLastError());
  45. while(1);
  46. } else {
  47. Serial.println(F("Wiring is correct and a card is present."));
  48. }
  49.  
  50. Serial.print(F("Looking for CHUCK.AFM... "));
  51. if(!SdPlay.setFile("CHUCK.AFM")) {
  52. Serial.println(F(" not found on card! Error code: "));
  53. Serial.println(SdPlay.getLastError());
  54. while(1);
  55. } else {
  56. Serial.println(F("found."));
  57. }
  58.  
  59. Serial.print(F("Playing... "));
  60. SdPlay.play();
  61. while(!SdPlay.isStopped()) {
  62. ; // no worker needed anymore :-)
  63. }
  64. Serial.println(F("done."));
  65. SdPlay.deInit();
  66. }
  67.  
  68.  
  69. void loop(void) {
  70.  
  71. // read the state of the pushbutton value:
  72. buttonState = digitalRead(buttonPin);
  73.  
  74. // check if the pushbutton is pressed.
  75. // if it is, the buttonState is HIGH:
  76. if (buttonState == HIGH) {
  77. // turn LED on:
  78. digitalWrite(ledPin, HIGH);
  79. }
  80. else {
  81. // turn LED off:
  82. digitalWrite(ledPin, LOW);
  83. }
  84.  
  85. // Open serial communications and wait for port to open:
  86. Serial.begin(9600);
  87.  
  88. int sensorValue = analogRead(A0);
  89.  
  90. while (!Serial) {
  91. ; // wait for serial port to connect. Needed for Leonardo only
  92. }
  93.  
  94. // Using F("...") to avoid wasting RAM
  95. Serial.print(F("\nInitializing SD card..."));
  96.  
  97. // If your SD card CS-Pin is not at Pin 4, enable and adapt the following line:
  98. SdPlay.setSDCSPin(10);
  99.  
  100. if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER)) {
  101. Serial.println(F("initialization failed. Things to check:"));
  102. Serial.println(F("* is a card is inserted?"));
  103. Serial.println(F("* Is your wiring correct?"));
  104. Serial.println(F("* maybe you need to change the chipSelect pin to match your shield or module?"));
  105. Serial.print(F("Error code: "));
  106. Serial.println(SdPlay.getLastError());
  107. while(1);
  108. } else {
  109. Serial.println(F("Wiring is correct and a card is present."));
  110. }
  111.  
  112. Serial.print(F("Looking for CHUCK.AFM... "));
  113. if(!SdPlay.setFile("CHUCK.AFM")) {
  114. Serial.println(F(" not found on card! Error code: "));
  115. Serial.println(SdPlay.getLastError());
  116. while(1);
  117. } else {
  118. Serial.println(F("found."));
  119. }
  120.  
  121. Serial.print(F("Playing... "));
  122. SdPlay.play();
  123. while(!SdPlay.isStopped()) {
  124. ; // no worker needed anymore :-)
  125. }
  126. Serial.println(F("done."));
  127. SdPlay.deInit();
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement