Motor set speed wont work when adding sounds

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

Moderators: adafruit_support_bill, adafruit

Motor set speed wont work when adding sounds

Postby amador137 » Fri Jan 25, 2013 7:22 pm

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.
amador137
 
Posts: 3
Joined: Tue Apr 03, 2012 7:07 am

Re: Motor set speed wont work when adding sounds

Postby franklin97355 » Sat Jan 26, 2013 12:21 am

Does it play the sound more than once?
User avatar
franklin97355
 
Posts: 1706
Joined: Mon Apr 21, 2008 1:33 pm

Re: Motor set speed wont work when adding sounds

Postby adafruit_support_bill » Sat Jan 26, 2013 7:09 am

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.
User avatar
adafruit_support_bill
 
Posts: 15918
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor set speed wont work when adding sounds

Postby amador137 » Sat Jan 26, 2013 6:45 pm

okay will do . will post what happens.
amador137
 
Posts: 3
Joined: Tue Apr 03, 2012 7:07 am


Return to Arduino Shields from Adafruit

Who is online

Users browsing this forum: No registered users and 4 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]