Motor set speed wont work when adding sounds

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
amador137
 
Posts: 3
Joined: Tue Apr 03, 2012 8:07 am

Motor set speed wont work when adding sounds

Post by amador137 »

Here is the code:

Code: Select all

/*
  Melody
 
 Plays a melody 
 
 circuit:
 * 8-ohm speaker on digital pin 8
 
 created 21 Jan 2010
 modified 30 Aug 2011
 by Tom Igoe 

This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/Tone
 
 */
 #include "pitches.h"
 #include <AFMotor.h>
 
AF_DCMotor motor(1);
AF_DCMotor motor2(2);

const int switchoff = 0;

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };

void setup() {
  

  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(9, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(9);
    if(thisNote == 8){
    break;
    }
   
  }
  
     motor.setSpeed(250);
     motor2.setSpeed(250); 
    
    
}

void loop() {
  
  motor.run(FORWARD);
  motor2.run(FORWARD);
}

sounds work but not the motor. I did the motor test example and motor works just fine.So i know the problem is not the motors. The problem is when I add sound the motor wont run at all. It just plays the sound and thats it. What I need is to be able to play the sound/music then move the dc motor. Please help.

User avatar
Franklin97355
 
Posts: 23903
Joined: Mon Apr 21, 2008 2:33 pm

Re: Motor set speed wont work when adding sounds

Post by Franklin97355 »

Does it play the sound more than once?

User avatar
adafruit_support_bill
 
Posts: 88040
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor set speed wont work when adding sounds

Post by adafruit_support_bill »

Try using motors 3 & 4. I'm not sure which timer Melody uses, but I suspect it is the same one used for the motor 1/2 speed control.

amador137
 
Posts: 3
Joined: Tue Apr 03, 2012 8:07 am

Re: Motor set speed wont work when adding sounds

Post by amador137 »

okay will do . will post what happens.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”