Go Down

Topic: arduino waveshield - servo motor problem (Read 889 times) previous topic - next topic

packingtape

hi everyone :) i need help im making my project with servo motors and waveshield. im having problem with waveshield when the servo motor is attach to arduino.. the sound is not working.. :( but when i remove the servo motors to my circuit the sounds work. i have 2 supply, one for servo motors and 1 for the whole circuit..

i used gizduino x arduino
http://www.e-gizmo.com/KIT/gizDuino%20X.html

and wave shield from ebay.
http://www.ebay.com/itm/Wave-Sound-Shield-Module-V1-0-Arduino-Compatible-/270941553333?pt=LH_DefaultDomain_0&hash=item3f156002b5

my source code


// waveshield
int RST = 3;
int CLK = 9;
int DAT = 8;
// left repulsor
int rightPin = 16;
int ledPin = 6;   
int button = 0;

//Right repulsor
int leftPin = 20;
int ledPin2 = 4;   
int button2 = 0;
//servo
#include <Servo.h>
//flaps
int swpinservo = 22;
Servo left;
Servo right;
//light
int boosterled = 11;

//helm
#include <Bounce.h>
#define BUTTON 14
#define LED 13
Servo helmet;
int ledValue = LOW;
Bounce bouncer = Bounce( BUTTON, 5 );



void pew(){
  //light dimming in
  analogWrite(ledPin, 5);
  delay(300);
  analogWrite(ledPin, 10);
  delay(300);
  analogWrite(ledPin, 15);
  delay(300);
  analogWrite(ledPin, 20);
  delay(300);
  analogWrite(ledPin, 25);
  delay(200);
  analogWrite(ledPin, 30);
  delay(200);
  analogWrite(ledPin, 35);
  delay(200);
  analogWrite(ledPin, 40);
  delay(200);
  analogWrite(ledPin, 45);
  delay(400);
 
  analogWrite(ledPin, 50);
  delay(300);

 
analogWrite(ledPin, 255);
delay(100);
analogWrite(ledPin, 0);
delay(100);
analogWrite(ledPin, 255);
delay(100);

analogWrite(ledPin,20);
delay(200);

         
 
}

void pewew(){
  //light dimming out
 
   analogWrite(ledPin, 20);
  delay(300);
  analogWrite(ledPin, 18);
  delay(300);
  analogWrite(ledPin, 16);
  delay(300);
  analogWrite(ledPin, 14);
delay(300);
  analogWrite(ledPin, 12);
delay(300);


  analogWrite(ledPin, 10);
  delay(300);
  analogWrite(ledPin, 8);
  delay(300);
  analogWrite(ledPin, 6);
  delay(300);
  analogWrite(ledPin, 4);
delay(300);
  analogWrite(ledPin, 2);
delay(300);

analogWrite(ledPin,0);
 
}


void setup() { 
    // wave shield
    pinMode(RST, OUTPUT);
    pinMode(CLK, OUTPUT);
    pinMode(DAT, OUTPUT);
    digitalWrite(RST, HIGH);
    digitalWrite(CLK, HIGH);
    digitalWrite(DAT, HIGH);
    digitalWrite(RST, LOW);
    delay(5);
    digitalWrite(RST, HIGH);
    delay(300);

    // right repulsor
      pinMode(rightPin, INPUT);
    pinMode(ledPin, OUTPUT);
    digitalWrite(button, LOW); /* Set button initially as LOW */
    //left repulsor
      pinMode(leftPin, INPUT);
    pinMode(ledPin2, OUTPUT);
    digitalWrite(button2, LOW); /* Set button initially as LOW */
   
          //servo flaps
        left.attach(7);
        right.attach(5);
   pinMode(swpinservo, INPUT);
   pinMode(boosterled, OUTPUT);
         //status position
         left.write(128);
         right.write(44);
         
         //helmet
         pinMode(BUTTON,INPUT);
        pinMode(LED,OUTPUT);
        helmet.attach(1);
        helmet.write(0);




}

void loop() {

  //right repulosr
  if(digitalRead(rightPin) == HIGH && button == 0){
  delay(100); 
 
   button = 1;
//sound
 
  send(0x0001);
  delay(100);
 
  send(0xfff7);
  delay(600);
   
  //light
pew();
send(0xfffe);// pause



  } 
  else if(digitalRead(rightPin) == LOW && button == 1){
    button = 0;
   
    pewew();
     
 
      send(0x0003);
      delay(350);
   

    send(0xfff7);
 

   }
   
//left repulsor
if(digitalRead(leftPin) == HIGH && button2 == 0){
  delay(200);  /
 
   button2 = 1;
//sound
 
  send(0x0002);
  delay(100);
 
//light
analogWrite(ledPin2, 5);
  delay(100);
  analogWrite(ledPin2, 20);
  delay(100);
  analogWrite(ledPin2, 40);
  delay(100);
  analogWrite(ledPin2, 50);
  delay(100);
  analogWrite(ledPin2, 70);
  delay(100); 
analogWrite(ledPin2, 255);
delay(100);
analogWrite(ledPin2, 0);
delay(100);
analogWrite(ledPin2, 255);
delay(100);
analogWrite(ledPin2,60);

//stop
  delay( 200);
  send(0xfff7);//set voice volumn to 7
  delay(300);
   


send(0xfffe);// pause

  } 
  else if(digitalRead(leftPin) == LOW && button2 == 1){
    button2 = 0;
  analogWrite(ledPin2, 20);
  delay(100);
 

   
  analogWrite(ledPin2, 12);
  delay(100);


  analogWrite(ledPin2, 6);
  delay(100);
  analogWrite(ledPin2, 0);


     
   }

  //------- air flaps function
              if (digitalRead(swpinservo) == HIGH)
             {
                  delay(50);
                   left.write(50);
               right.write(125);
              delay(200);
             
 
         digitalWrite(boosterled,HIGH);
             
               
}

   else{
                  left.write(128);
                 right.write(44);
         
            digitalWrite(boosterled,LOW);
      }
   
    //--------------- helmet function
      if ( bouncer.update() ) {
     if ( bouncer.read() == HIGH) {
       if ( ledValue == LOW ) {
         delay(10);
          helmet.write(4);
          delay(700);
         ledValue = HIGH;
       } else {
         helmet.write(175);
         ledValue = LOW;
       }
       
       digitalWrite(LED,ledValue);
     }
   }








 
}


//function of wave shield data
void send(int data)
{
  digitalWrite(CLK, LOW);
  delay(2);
  for (int i=15; i>=0; i--)
  {
    delayMicroseconds(50);
    if((data>>i)&0x0001 >0)
      {
        digitalWrite(DAT, HIGH);
        //Serial.print(1);
      }
    else
       {
         digitalWrite(DAT, LOW);
        // Serial.print(0);
       }
    delayMicroseconds(50);
    digitalWrite(CLK, HIGH);
    delayMicroseconds(50);
   
    if(i>0)
    digitalWrite(DAT, LOW);
    else
    digitalWrite(DAT, HIGH);
    delayMicroseconds(50);
   
    if(i>0)
    digitalWrite(CLK, LOW);
    else
    digitalWrite(CLK, HIGH);
  }
 
  delay(20);
}

codlink

#1
Dec 17, 2012, 01:03 pm Last Edit: Dec 17, 2012, 01:05 pm by codlink Reason: 1
Quote
analogWrite(ledPin, 10);
  delay(300);
  analogWrite(ledPin, 8);
  delay(300);
  analogWrite(ledPin, 6);


Please Modify your post and highlight all of your code, then press the # button in the editor.  Those awesome smilies will go away and we can read your code.

How is your motor wired?
//LiNK

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy