Advertisement
Guest User

Untitled

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