New to arduino, Need help with this code!

Hi i am new to arduino and need a bit of help

I am trying to make a code so when you click the button on the breadboard it will light up lights in a patten move a servo moter and play a quick sound effect. i have done all of them in there own files and have now combind the lights and servo moter but when i try and add the sound effect it will not let me. This is the code.

#include <SimpleSDAudio.h>
const int buttonPin = 1;
const int led2Pin = 7;
const int led3Pin = 6;
const int led4Pin = 5;
const int led5Pin = 4;
const int led6Pin = 3;
const int led7Pin = 2;
int buttonState = 0;
#include <Servo.h>
int servoPin = 8;
Servo Servo1;
void setup() {
const int BUTTON_PIN = 1;
const int LED_1PIN = 7;
const int LED_2PIN = 6;
const int LED_3PIN = 5;
const int LED_4PIN = 4;
const int LED_5PIN = 3;
const int LED_6PIN = 2;
Servo1.attach(servoPin);
Serial.begin(9600);
pinMode(1,INPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(3,OUTPUT);
pinMode(2,OUTPUT);
SdPlay.setSDCSPin(10);
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))
{ while(1); }
if(!SdPlay.setFile("8.wav")){;}
}
void loop(){
SdPlay.play();
while(!SdPlay.isStopped()){;}
buttonState = digitalRead(buttonPin);
delay (0);
if (buttonState == LOW) {
digitalWrite(7,LOW);
delay(20);
digitalWrite(7,HIGH);
delay(20);
digitalWrite(7,LOW);
delay(20);
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
delay(20);
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
delay(20);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
delay(20);
digitalWrite(4,HIGH);
digitalWrite(3,LOW);
delay(20);
digitalWrite(4,LOW);
digitalWrite(3,HIGH);
delay(20);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
delay(20);
digitalWrite(2,HIGH);
delay(20);
digitalWrite(2,LOW);
delay(20);
Servo1.write(90);
delay(0);
Servo1.write(30);
delay(1500);
Servo1.write(90);
delay(1000);
} else {
digitalWrite(7,LOW);
delay(200);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
delay(0);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
delay(0);
digitalWrite(2,LOW);
delay(0);}
}

This is the Error when i try and verify or Upload.

C:\Users\Rad\Documents\Arduino\Chamber_ult\Chamber_ult.ino: In function 'void setup()':

C:\Users\Rad\Documents\Arduino\Chamber_ult\Chamber_ult.ino:34:27: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

if(!SdPlay.setFile("8.wav")){;}

                       ^

libraries\Servo\avr\Servo.cpp.o (symbol from plugin): In function `ServoCount':

(.text+0x0): multiple definition of `__vector_11'

libraries\SimpleSDAudio\SimpleSDAudio.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Uno.

Please help as this is very anoying getting this far into the code and the sound not working.

When I saw the title of your topic, I thought to myself "I bet this guy hasn't used code tags". So that's at least 2 forum rules broken! Please read the forum guide and fix those and any other advice you didn't follow. The forum guide link can be found in the sticky posts at the top of each forum section.

At least you didn't post in the "Installation and troubleshooting" or "introductory tutorials" sections! :wink:

Your two libraries both want to use the same timer, so it's time to find another library for the servos.
I suggest you look for the ServoTimer2 library.

Thanks but how do i run it on this???

Have you installed the library?
If so, then simply change the #include to use the new library, change the type of your Servo object to match, and recompile.
If you have any problems, take a look at the library's examples.

1 Like

And note that ServoTimer2write() uses pulse width in microseconds NOT angles so write(90) becomes write(1500) and write(30) becomes write(900). Those values are approximate as they vary from servo to servo.

Steve

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.