Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Music Maker Affects Timing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Music Maker Affects Timing

by augydoggy on Tue Jan 17, 2017 7:15 pm

What was wrong with the way I declared it at the beginning of the loop?

Code: Select all | TOGGLE FULL SIZE
loopStartTime = rtc.now();

augydoggy
 
Posts: 64
Joined: Mon Jun 06, 2016 6:36 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Tue Jan 17, 2017 9:25 pm

This is a variable declaration. It tells the compiler the type (DateTime) and the name (loopStartTime) of the variable.
Code: Select all | TOGGLE FULL SIZE
DateTime loopStartTime;


This is an assignment statement. It assumes that the variable "loopTime" has already been declared.
Code: Select all | TOGGLE FULL SIZE
loopStartTime = rtc.now();


This is a variable declaration, combined with an assignment statement. It specifies the type, the name and the initial value of the variable.
Code: Select all | TOGGLE FULL SIZE
DateTime loopStartTime = rtc.now();

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Music Maker Affects Timing

by augydoggy on Wed Jan 18, 2017 6:55 am

Excellent explanation. Thank you.

I added the variable declaration combined with an assignment statement to the beginning of the loop. I also added the code for loopStartTime to calculate the time measurements within the loop. I'm still getting errors. I'll post the void coalbucket sketch and then the errors.

Code: Select all | TOGGLE FULL SIZE
void coalBucket() {
  // play sounds of coaling tower bucket operation
  // run motor to animate coal bucket.
  // initialize RTC start time
  DateTime now = rtc.now();  // defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track005.wav");  // begin soundtrack
  while(rtc.now().unixtime() - startTime < 5);  // pause 5 seconds after startTime for sound of engine starting
  for (; runXTimes < 8; runXTimes++) {  // begin bucket filling loop, repeat 8 times
  DateTime loopStartTime = rtc.now();
  while(rtc.now().unixtime() - loopStartTime < 4 + 5);  // pause while bucket fills, 4 seconds
  coalBucketMotor ->run(FORWARD);  // start motor in forward
  while(rtc.now().unixtime() - loopStartTime < 14 + 5);  // bucket raises to top of tower, 10 seconds
  coalBucketMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - loopStartTime < 18 + 5);  // pause while bucket dumps, 4 seconds
  coalBucketMotor ->run(BACKWARD);  // start motor in backward
  while(rtc.now().unixtime() - loopStartTime < 28 + 5);  // bucket is lowered into pit, 10 seconds
  coalBucketMotor ->run(RELEASE);}  // stop motor, end of filling loop after 8 repetitions
  while(rtc.now().unixtime() - startTime < 235);  // allow 6 seconds for sound of engine stopping
  musicPlayer.stopPlaying();  // stop playing sound file since the animation is done

  }


Code: Select all | TOGGLE FULL SIZE
Arduino: 1.6.9 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WARNING: Spurious .github folder in 'RTClib' library
WARNING: Spurious .github folder in 'Adafruit Motor Shield V2 Library' library
WARNING: Spurious .github folder in 'Adafruit PWM Servo Driver Library' library
WARNING: Spurious .github folder in 'Adafruit VS1053 Library' library
C:\Users\Tom\Documents\Arduino\Adafruit_Motor_Shield_V2_Library_master\examples\Engine Service Terminal\Engine_Terminal_Master-2\Engine_Terminal_Master-2.ino: In function 'void coalBucket()':

Engine_Terminal_Master-2:343: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 4 + 5);  // pause while bucket fills, 4 seconds

                              ^

Engine_Terminal_Master-2:345: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 14 + 5);  // bucket raises to top of tower, 10 seconds

                              ^

Engine_Terminal_Master-2:347: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 18 + 5);  // pause while bucket dumps, 4 seconds

                              ^

Engine_Terminal_Master-2:349: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 28 + 5);  // bucket is lowered into pit, 10 seconds

                              ^

exit status 1
no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

Invalid library found in C:\Users\Tom\Documents\Arduino\libraries\BaseStation1.2.1: C:\Users\Tom\Documents\Arduino\libraries\BaseStation1.2.1
Invalid library found in C:\Users\Tom\Documents\Arduino\libraries\Controller1.1.0: C:\Users\Tom\Documents\Arduino\libraries\Controller1.1.0
Invalid library found in C:\Users\Tom\Documents\Arduino\libraries\Sparkfun-MP3-Player-Shield-Arduino-Library-master: C:\Users\Tom\Documents\Arduino\libraries\Sparkfun-MP3-Player-Shield-Arduino-Library-master

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

augydoggy
 
Posts: 64
Joined: Mon Jun 06, 2016 6:36 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Wed Jan 18, 2017 7:20 am

Sorry about that. I should have had you define loopStartTime as a 32-bit 'unixtime' so that the math would work:

Code: Select all | TOGGLE FULL SIZE
  uint32_t loopStartTime = rtc.now().unixtime();

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Music Maker Affects Timing

by augydoggy on Wed Jan 18, 2017 7:54 am

I had actually attempted this once already. in the code below I've added your line to define loopStartTime as unixtime. I think I understand what we're doing here but I'm still getting errors. Can you see what I'm doing wrong?

Code: Select all | TOGGLE FULL SIZE
void coalBucket() {
  // play sounds of coaling tower bucket operation
  // run motor to animate coal bucket.
  // initialize RTC start time
  DateTime now = rtc.now();  // defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track005.wav");  // begin soundtrack
  while(rtc.now().unixtime() - startTime < 5);  // pause 5 seconds after startTime for sound of engine starting
  for (; runXTimes < 8; runXTimes++) {  // begin bucket filling loop, repeat 8 times
  DateTime loopStartTime = rtc.now();  // defines loopStartTime
  uint32_loopStartTime = rtc.now().unixtime();  // defines loopStartTime in unixtime()
  while(rtc.now().unixtime() - loopStartTime < 4 + 5);  // pause while bucket fills, 4 seconds
  coalBucketMotor ->run(FORWARD);  // start motor in forward
  while(rtc.now().unixtime() - loopStartTime < 14 + 5);  // bucket raises to top of tower, 10 seconds
  coalBucketMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - loopStartTime < 18 + 5);  // pause while bucket dumps, 4 seconds
  coalBucketMotor ->run(BACKWARD);  // start motor in backward
  while(rtc.now().unixtime() - loopStartTime < 28 + 5);  // bucket is lowered into pit, 10 seconds
  coalBucketMotor ->run(RELEASE);}  // stop motor, end of filling loop after 8 repetitions
  while(rtc.now().unixtime() - startTime < 235);  // allow 6 seconds for sound of engine stopping
  musicPlayer.stopPlaying();  // stop playing sound file since the animation is done

  }


Code: Select all | TOGGLE FULL SIZE
Arduino: 1.6.9 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WARNING: Spurious .github folder in 'RTClib' library
WARNING: Spurious .github folder in 'Adafruit Motor Shield V2 Library' library
WARNING: Spurious .github folder in 'Adafruit PWM Servo Driver Library' library
WARNING: Spurious .github folder in 'Adafruit VS1053 Library' library
C:\Users\Tom\Documents\Arduino\Adafruit_Motor_Shield_V2_Library_master\examples\Engine Service Terminal\Engine_Terminal_Master-2\Engine_Terminal_Master-2.ino: In function 'void coalBucket()':

Engine_Terminal_Master-2:343: error: 'uint32_loopStartTime' was not declared in this scope

   uint32_loopStartTime = rtc.now().unixtime();  // defines loopStartTime in unixtime()

   ^

Engine_Terminal_Master-2:344: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 4 + 5);  // pause while bucket fills, 4 seconds

                              ^

Engine_Terminal_Master-2:346: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 14 + 5);  // bucket raises to top of tower, 10 seconds

                              ^

Engine_Terminal_Master-2:348: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 18 + 5);  // pause while bucket dumps, 4 seconds

                              ^

Engine_Terminal_Master-2:350: error: no match for 'operator-' (operand types are 'uint32_t {aka long unsigned int}' and 'DateTime')

   while(rtc.now().unixtime() - loopStartTime < 28 + 5);  // bucket is lowered into pit, 10 seconds

                              ^

exit status 1
'uint32_loopStartTime' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

augydoggy
 
Posts: 64
Joined: Mon Jun 06, 2016 6:36 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Wed Jan 18, 2017 8:08 am

Code: Select all | TOGGLE FULL SIZE
  DateTime loopStartTime = rtc.now();  // defines loopStartTime

That is the old declaration of a DateTime variable called loopStartTime.

Code: Select all | TOGGLE FULL SIZE
  uint32_loopStartTime = rtc.now().unixtime();  // defines loopStartTime in unixtime()

The compiler is seeing that as an assignment statement for an undeclared variable named "uint32_loopStartTime".

Which gives you the error message:
Engine_Terminal_Master-2:343: error: 'uint32_loopStartTime' was not declared in this scope

uint32_loopStartTime = rtc.now().unixtime(); // defines loopStartTime in unixtime()

^


Note that uint32_loopStartTime is not the same thing as uint32_t loopStartTime

You need to delete the old DateTime declaration and replace it with a uint32_t declaration.
Code: Select all | TOGGLE FULL SIZE
  uint32_t loopStartTime = rtc.now().unixtime();  // defines loopStartTime in unixtime()

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Music Maker Affects Timing

by augydoggy on Wed Jan 18, 2017 8:34 am

Bill - OK, that flew. The entire sketch now compiles! Awesome! I'll send you a link to YouTube when I get everything operational.

As a model railroader I think this will be helpful to a lot of people working on similar animation projects.

You have incredible patience. I really appreciate all your help getting this sketch going. This is my first Arduino project and I've learned a lot here. The explanations of code have really helped too.

- Tom

augydoggy
 
Posts: 64
Joined: Mon Jun 06, 2016 6:36 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Wed Jan 18, 2017 8:35 am

Great! Looking forward to seeing the videos.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Music Maker Affects Timing

by augydoggy on Wed Jan 18, 2017 12:54 pm

Looks like I'm not there yet. Two issues.

1) If I don't hit reset when I first start up void waterspout then the sound file won't play. Is there code to start it out with a reset?

2) The wav file still gets trashed, mucho distortion. Mp3 plays fine. Playing MP3 is a last resort. I would really prefer WAV.

Code: Select all | TOGGLE FULL SIZE
// Model railroad animations sketch




// include SPI, MP3 and SD libraries

#include <SPI.h>

#include <Adafruit_VS1053.h>

#include <SD.h>

#include <Wire.h>

#include <Adafruit_MotorShield.h>

#include "utility/Adafruit_MS_PWMServoDriver.h"

#include "RTClib.h"




// define the pins used

//#define CLK 13       // SPI Clock, shared with SD card

//#define MISO 12      // Input data, from VS1053/SD card

//#define MOSI 11      // Output data, to VS1053/SD card

// Connect CLK, MISO and MOSI to hardware SPI pins.

// See http://arduino.cc/en/Reference/SPI "Connections"




// These are the pins used for the music maker shield

#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)

#define SHIELD_CS     7      // VS1053 chip select pin (output)

#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)




// These are common pins between breakout and shield

#define CARDCS 4     // Card chip select pin

// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt

#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin




Adafruit_VS1053_FilePlayer musicPlayer =

  // create shield-example object!

  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);




RTC_DS3231 rtc;

// These are the pins used for the RTC

#define SDA 20       // RTC I2C clock

#define SCL 21       // RTC I2C data



// Create the motor shield object with the default I2C address

Adafruit_MotorShield AFMS = Adafruit_MotorShield();




// Assign some motors.

Adafruit_DCMotor *sandChuteMotor = AFMS.getMotor(1);

Adafruit_DCMotor *coalChuteMotor = AFMS.getMotor(2);

Adafruit_DCMotor *coalBucketMotor = AFMS.getMotor(3);

Adafruit_DCMotor *waterSpoutMotor = AFMS.getMotor(4);




int runXTimes = 0;




const int BUTTON_A = 21; // pin 21

const int BUTTON_B = 22; // pin 22

const int BUTTON_C = 23; // pin 23

const int BUTTON_D = 24; // pin 24

const int BUTTON_E = 25; // pin 25

const int BUTTON_F = 26; // pin 26

const int BUTTON_G = 27; // pin 27


void setup() {
 
const int BUTTON_A = 21;  // ashpit

const int BUTTON_B = 22;  // sandhouse chute

const int BUTTON_C = 23;  // sandhouse compressor

const int BUTTON_D = 24;  // coaling tower chute

const int BUTTON_E = 25;  // coaling tower bucket

const int BUTTON_F = 26;  // water tank spout

const int BUTTON_G = 27;  // coal pit







 // initialize seven inputs for use with pushbuttons. Normally HIGH, if pushed, goes to LOW.

  pinMode(BUTTON_A, INPUT_PULLUP);

  pinMode(BUTTON_B, INPUT_PULLUP);

  pinMode(BUTTON_C, INPUT_PULLUP);

  pinMode(BUTTON_D, INPUT_PULLUP);

  pinMode(BUTTON_E, INPUT_PULLUP);

  pinMode(BUTTON_F, INPUT_PULLUP);

  pinMode(BUTTON_G, INPUT_PULLUP);

  Serial.begin(9600);

  if (! musicPlayer.begin()) {
   
    // initialise the music player

     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));

     while (1);   // Note that this loops forever if it can't find the musicPlayer.

  }
 
  SD.begin(CARDCS); 
 
  // initialise the SD card

  // Set volume for left, right channels. lower numbers == louder volume!

  musicPlayer.setVolume(30,30);




  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background audio playing

  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int





  AFMS.begin();  // create with the default frequency 1.6KHz

  sandChuteMotor->setSpeed(100);

  coalChuteMotor->setSpeed(100);

  coalBucketMotor->setSpeed(100);

  waterSpoutMotor->setSpeed(100);

 
}

void loop() {
  if (digitalRead(BUTTON_A) == LOW) {

    ashPit();   // button A was pressed

  }

  if (digitalRead(BUTTON_B) == LOW) {

    sandChute();    // button B was pushed

  }

  if (digitalRead(BUTTON_C) == LOW) {

    sandCompressor();    // button C was pressed

  }

  if (digitalRead(BUTTON_D) == LOW) {

    coalChute();    // button D was pressed

  }

  if (digitalRead(BUTTON_E) == LOW) {

    coalBucket();    // button E was pressed

  }

  if (digitalRead(BUTTON_F) == LOW) {

    waterSpout();    // button F was pressed

  }

  if (digitalRead(BUTTON_G) == LOW) {

    coalPit();    // button G was pressed

  }




}




void ashPit() {
  // play sound of fire and coals
  // sound file to drive LEDs, simulate fire and coals
  // initialize RTC start time
  DateTime now = rtc.now();  //defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track001.wav");  // start playing soundtrack
  while(rtc.now().unixtime() - startTime < 15);  // allow 15 seconds for soundtrack to play
  musicPlayer.stopPlaying();  // stop playing sound track

  }




void sandChute() {
  // play sand blowing sounds to go with chute operation
  // run motor to animate sand chute
  // initialize RTC start time
  DateTime now = rtc.now();  // defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track002.wav");  // begin soundtrack
  while(rtc.now().unixtime() - startTime < 15);  // delay motor for 15 seconds   
  sandChuteMotor ->run(FORWARD);  // start motor in forward
  while(rtc.now().unixtime() - startTime < 20);  // chute lowers to sand dome 5 seconds
  sandChuteMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - startTime < 35);  // sand flows into dome 15 seconds
  sandChuteMotor ->run(BACKWARD);  // start motor in reverse
  while(rtc.now().unixtime() - startTime < 40);  // chute raises to stored position 5 seconds
  sandChuteMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - startTime < 46);  // allow 6 seconds for soundtrack to complete
  musicPlayer.stopPlaying();  // stop playing sound file since the animation is done

}




void sandCompressor() {
  // sounds associated with sand drying process.
  // furnace and compressor sounds to go with door operation
  // initialize RTC start time
  DateTime now = rtc.now();  // defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track003.wav");  // begin soundtrack
  while(rtc.now().unixtime() - startTime < 15);  // allow 15 seconds for soundtrack to complete
  musicPlayer.stopPlaying();  // stop playing sound file since the animation is done

}







void coalChute() {
  // play sounds of coaling tower chute operation
  // run motor to animate coal chute. Use coalChuteMotor.
  // initialize RTC start time
  DateTime now = rtc.now();  //defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track004.wav");  // begin soundtrack
  while(rtc.now().unixtime() - startTime < 5);  // starts the motor 5 seconds after startTime
  coalChuteMotor ->run(FORWARD);  // start motor in forward
  while(rtc.now().unixtime() - startTime < 15);  // chute lowers for 10 seconds
  coalChuteMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - startTime < 60);  // coal drops into tender 45 seconds
  coalChuteMotor ->run(BACKWARD);  // start motor in reverse
  while(rtc.now().unixtime() - startTime < 70);  // chute raises to stored position 10 seconds
  coalChuteMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - startTime < 76);  // allow 6 seconds for soundtrack to complete
  musicPlayer.stopPlaying();  // stop playing sound file since the animation is done

  }




void coalBucket() {
  // play sounds of coaling tower bucket operation
  // run motor to animate coal bucket.
  // initialize RTC start time
  DateTime now = rtc.now();  // defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track005.wav");  // begin soundtrack
  while(rtc.now().unixtime() - startTime < 5);  // pause 5 seconds after startTime for sound of engine starting
  for (; runXTimes < 8; runXTimes++) {  // begin bucket filling loop, repeat 8 times
  uint32_t loopStartTime = rtc.now().unixtime();  // defines loopStartTime in unixtime()
  while(rtc.now().unixtime() - loopStartTime < 4 + 5);  // pause while bucket fills, 4 seconds
  coalBucketMotor ->run(FORWARD);  // start motor in forward
  while(rtc.now().unixtime() - loopStartTime < 14 + 5);  // bucket raises to top of tower, 10 seconds
  coalBucketMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - loopStartTime < 18 + 5);  // pause while bucket dumps, 4 seconds
  coalBucketMotor ->run(BACKWARD);  // start motor in backward
  while(rtc.now().unixtime() - loopStartTime < 28 + 5);  // bucket is lowered into pit, 10 seconds
  coalBucketMotor ->run(RELEASE);}  // stop motor, end of filling loop after 8 repetitions
  while(rtc.now().unixtime() - startTime < 235);  // allow 6 seconds for sound of engine stopping
  musicPlayer.stopPlaying();  // stop playing sound file since the animation is done

  }




void waterSpout() {
  // play sounds of water tank chute operation
  // run motor to animate water tank spout
  // initialize RTC start time
  DateTime now = rtc.now();  // defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track006.wav");  // play sounds of filling water in tender
  while(rtc.now().unixtime() - startTime < 10);  // starts the motor 10 seconds after startTime
  waterSpoutMotor ->run(FORWARD);  // start motor in forward
  while(rtc.now().unixtime() - startTime < 16);  // spout lowers for 6 seconds
  waterSpoutMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - startTime < 126);  // sound of water flowing for 110 seconds
  waterSpoutMotor ->run(BACKWARD);  // start motor in reverse
  while(rtc.now().unixtime() - startTime < 128);  // spout raises to stored position, 6 seconds
  waterSpoutMotor ->run(RELEASE);  // stop motor
  while(rtc.now().unixtime() - startTime < 134);  // allow six seconds for sound track to complete
  musicPlayer.stopPlaying();  // stop playing sound file

  }   




void coalPit() {
  // play sounds of coal pit filling operation
  // initialize RTC start time
  DateTime now = rtc.now();  // defines "rtc.now()"
  uint32_t startTime = rtc.now().unixtime();  // defines startTime as "now.unixtime()", the time you enter the function
  musicPlayer.startPlayingFile("track007.wav");  // begin sounds of coal pit operation
  while(rtc.now().unixtime() - startTime < 15);  // allow 15 seconds for soundtrack
  musicPlayer.stopPlaying();  // stop playing sound file since the animation is done

}

augydoggy
 
Posts: 64
Joined: Mon Jun 06, 2016 6:36 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Wed Jan 18, 2017 1:59 pm

1) Not sure why that would be. Does this only occur with the waterspout scene?
2) It looks like you are using "software SPI". This is considerably slower than hardware SPI. The Music Maker shield does support hardware SPI with the Mega:
https://learn.adafruit.com/adafruit-mus ... o-and-mega

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Music Maker Affects Timing

by augydoggy on Wed Jan 18, 2017 5:47 pm

The sound problem is not confined to the waterspout scene.

When I started using the Mega instead of the Uno I soldered the SPI jumpers and cut the traces for pins 11,12 and 13. In the beginning of my sketch is #include <SPI.h>. Can this be deleted since the jumpers are soldered in on the Mega? Could this be my problem with the WAV files?

About the reset code. Are you familiar with resetFunc()? Would that work OK for what I need, mentioned in previous post?

augydoggy
 
Posts: 64
Joined: Mon Jun 06, 2016 6:36 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Thu Jan 19, 2017 8:54 am

Not sure why a reset should be required. You can try the resetFunc() to see if it helps. However, it is not a full hardware reset, so it may not have any effect on the sound card.

Regarding the WAV file distortion, does this happen all the time, or only with motors running?

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Music Maker Affects Timing

by augydoggy on Thu Jan 19, 2017 9:43 am

The WAV file distortion begins right away at the beginning of the "scene". I'm using void waterspout currently because it's my only completed sound file but I did try using a different sound file with void sandChute and had the same problem.

I was looking into the SPI thing. I tried eliminating #include <SPI.h> but it didn't change anything. Further down in the sketch it defines CLK, MISO and MOSI pins and there's a note about info on SPI connections (see http://Arduino.cc/en/Reference/SPI "Connections"). I read through that and it said you can go in and change the speed. In ArduinoISP it has the following:

#define SPI_CLOCK (1000000/6).

Could I include this to set the SPI speed to match the Mega processor (16Mhz). Is there other code needed? Or am I just jumping on unknowns here?

augydoggy
 
Posts: 64
Joined: Mon Jun 06, 2016 6:36 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Thu Jan 19, 2017 10:21 am

I think you are OK with the SPI. I mis-read the code where you initialize it and thought you were using 'software SPI'.

Let me ask some of the other engineers if they have heard of similar issues with wav files.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Music Maker Affects Timing

by adafruit_support_bill on Thu Jan 19, 2017 10:28 am

One thing to try first. Let's add a delay in your 'while' timing loops. This will cut down on the i2c communication with the rtc. It is possible that is interfering with the playback.

Just add a "delay(10)" before the semicolon in your while loops as below:

Code: Select all | TOGGLE FULL SIZE
while(rtc.now().unixtime() - startTime < 10) delay(10);

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.