Please help me with the code

hi im trying to make a servo move wen i click a button
this is what ive done but i keep getting this eror message

exit status 1
Error compiling for board Arduino/Genuino Uno.

CODE
#include<SPI.h>
#include<Servo.h>
#include<Gamebuino.h>
Gamebuino gb;
Servo myservo;

int pos = 0;

void setup() {
myservo.attach(A4);
gb.begin();

}

void loop() {
if(gb.update()){

if(gb.buttons.repeat(BTN_RIGHT,1)){
for (pos = 0; pos <= 180; pos += 1)
myservo.write(pos);
}
}
}

you use myservo.attach(A4); but A4 is not defined
you have like for pos to declare A4 and initialize it
you should put gb.begin befoe too but it’s should not make change for this.

else the est of the prog seems clean

A4 should be defined by default because the Arduino IDE knows that the Arduino Uno (ATMega328P, same microprocessor as used for the Makerbuino) has an analog input/output labeled “A4”.

@Samilpatel
I can’t spot any error within the code.

This can’t be the whole error message. Please copy and paste the whole text within the compiling window.
Do you really need to use the analog input/output A4?

[EN] OK, so it’s could be good to test to replace A4 by the pin number in the code and to test if the program compile with this change. If it’s compile, we found the problem, else, we can be sure that A4 is not the reason of the error.
[FR] OK, il pourrait être intéressant quand même de tester en remplaçant A4 par le numéro de sortie directement et voir ce que ça donne, si ça compile ou non. Ca permettrait d’éliminer cette cause rapidement

this is full error message
exit status 1
Error compiling for board Arduino/Genuino Uno.

i tried changing a4 with 9 and still didn’t compile
anything else that might be wrong

Have you try begin by gb.begin();and put myservo.attach(A4); after ?
Nothing which can explain the problem but to make it easiest to move into yout programm and correct it, you should use indentation.
For example for:
void loop() {
if(gb.update()){

if(gb.buttons.repeat(BTN_RIGHT,1)){
for (pos = 0; pos <= 180; pos += 1)
myservo.write(pos);
}
}
}

it easier to read if you write it as:

void loop() {
   if(gb.update()){
      if(gb.buttons.repeat(BTN_RIGHT,1)){
         for (pos = 0; pos <= 180; pos += 1)
            myservo.write(pos);
      }
   }
}

You don’t loose time to identify your blocs, but your problem don’t seems to be linked to that. But it’s maybe just a display problem as you hadn’ used the Preformated text format into your message.
But if i was you i’ll try to put gb.begin just after the setup line as it’s better to make the init of the gb hardware before starting to use it…

Hey folks, thank you for helping Samil out.

Arduino’s Servo library uses Timer1 for generating the signal for controlling servos.
The Gamebuino library is using Timer1 too for sound generation.

I think this is causing the problem.

Please, check this article and try utilising timer2 for this cause:

Cheers!

1 Like

That’s what I’ve found out during the weekend too. I’m pretty sure that this is causing the problem. I’ve copied and compiled the code and there we’re some more lines of errors, not just “exit status 1
Error compiling for board Arduino/Genuino Uno.”.

D:\Users\XXXXXX\AppData\Local\Temp\arduino_build_566975\libraries\Gamebuino\utility\Sound.cpp.o (symbol from plugin): In function `Sound::command(unsigned char, unsigned char, signed char, unsigned char)’:

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

D:\Users\XXXXXX\AppData\Local\Temp\arduino_build_566975\libraries\Servo\avr\Servo.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/Genuino Uno.

There you can see that the Servo library is interfereing with the gamebuino (sound) library.
So I guess using the tutorial provided by @albertgajsak should fix your problem.