This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
DUDA Error compilando para la tarjeta Arduino/Genuino Uno. Necesito ayuda
#1
Triste 
Muy buenas tengo un problema al compilar el código de Arduino pero este lo tengo bien no entiendo que pasa, tengo 17 años y no comprendo muy bien aún el lenguaje C. Les dejo mi código por si pueden y quieren ayudarme gracias. Estoy subiéndolo desde un Mac OS Sierra a placa Arduino Genuino UNO.

Muchas gracias.

[/code]

#include <Servo.h>


Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

char a;
String readString;

void setup( ) {
  pinMode(13,OUTPUT);
  servo1.attach(8);
  servo2.attach(9);
  servo3.attach(10);
  servo4.attach(11);
  Serial.begin(9600);
servo1.write(8);
servo2.write(100);
servo3.write(164);
servo4.write(90);
delay (10);
}
int motor1();
int motor2();
int motor3();
int motor4();

void loop() {
 if (Serial.available() ) {
  
  a = Serial.read();

  if (a=='A') {
   motor1() ;
  }

  if (a=='B') {
   motor2();
  }

  if (a=='C') {
   motor3();
  }

  if (a=='D') {
    motor4();
  }

  if (a=='E') {
    digitalWrite(13,HIGH);
    delay (10);
  }

  if (a=='F') {
    digitalWrite(13,LOW);
    delay (10);
  }
 }

 void   motor1(); 
 {
  delay (10);
  while (Serial.available() ) {

    char c = Serial.read();
    readString += c;
    
  }
  if (readString.length() >0) {
    Serial.println (readString.toInt() );
    servo1.write (readString.toInt() );
    readString="";
  }
 }



 void   motor2();
 {
  delay (10);
  while (Serial.available() ) {

    char c = Serial.read();
    readString += c;
    
  }
  if (readString.length() >0) {
    Serial.println (readString.toInt() );
    servo2.write (readString.toInt() );
    readString="";
  }
 }



 void   motor3();
 {
  delay (10);
  while (Serial.available() ) {

    char c = Serial.read();
    readString += c;
    
  }
  if (readString.length() >0) {
    Serial.println (readString.toInt() );
    servo3.write (readString.toInt() );
    readString="";
  }
 }



  void   motor4();
  {
  delay (10);
  while (Serial.available() ) {

    char c = Serial.read();
    readString += c;
    
  }
  if (readString.length() >0) {
    Serial.println (readString.toInt() );
    servo4.write (readString.toInt() );
    readString="";
  }
 }


}

[/code]
  Responder
#2
mejor pega el mensaje de error que te genera!
  Responder
#3
El mensaje de error que sale en la consola suele ayudar bastante, sobretodo si son errores de compilación. Tabular bien también ayuda, ArduinoIDE tiene función de auto-tabulacion, en Windows es crtl+t, puedea buscarlo en la barra de herramientas.


Creo que el fallo es que estás definiendo tus funciones dentro del loop. Cierra el loop y después defines tus funciones, sólo tienes que mover el último corchete.

Además tampoco entiendo esto que tienes justo después del setup.
int motor1();
int motor2();
int motor3();
int motor4();
Borralas, la función está bien definida sin ellas, sólo que en el sitio incorrecto.
  Responder
#4
Arduino:1.8.8 (Mac OS X), Tarjeta:"Arduino/Genuino Uno"

/var/folders/c5/8b9sq92s60b9c5zx8y3cpjzr0000gn/T//ccH0kJgs.ltrans0.ltrans.o: In function `loop':
/Users/alvaro/Documents/Arduino/sketch_apr26c/sketch_apr26c.ino:36: undefined reference to `motor1()'
/Users/alvaro/Documents/Arduino/sketch_apr26c/sketch_apr26c.ino:40: undefined reference to `motor2()'
/Users/alvaro/Documents/Arduino/sketch_apr26c/sketch_apr26c.ino:44: undefined reference to `motor3()'
/Users/alvaro/Documents/Arduino/sketch_apr26c/sketch_apr26c.ino:48: undefined reference to `motor4()'
collect2: error: ld returned 1 exit status
exit status 1
Error compilando para la tarjeta Arduino/Genuino Uno.

Este informe podría contener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.
  Responder
#5
#include <Servo.h>


Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

char a;
String readString;

void setup( ) {
pinMode(13,OUTPUT);
servo1.attach(8);
servo2.attach(9);
servo3.attach(10);
servo4.attach(11);
Serial.begin(9600);
servo1.write(8);
servo2.write(100);
servo3.write(164);
servo4.write(90);
delay (10);
}

void loop() {
if (Serial.available() ) {

a = Serial.read();

if (a=='A') {
motor1() ;
}

if (a=='B') {
motor2();
}

if (a=='C') {
motor3();
}

if (a=='D') {
motor4();
}

if (a=='E') {
digitalWrite(13,HIGH);
delay (10);
}

if (a=='F') {
digitalWrite(13,LOW);
delay (10);
}
}

}

void motor1();
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo1.write (readString.toInt() );
readString="";
}
}



void motor2();
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo2.write (readString.toInt() );
readString="";
}
}



void motor3();
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo3.write (readString.toInt() );
readString="";
}
}



void motor4();
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo4.write (readString.toInt() );
readString="";
}
}

Prueba a ver pero mejor si lo entiendes. Las funciones motor1 motor2 etc tienen que estar al mismo nivel que las funciones setup y loop, no dentro de éstas.

Mejor por aquí que por privado por si sirve de ayuda para otros.
  Responder
#6
Lo ve es que no tiene sentido ahora me pone eso, siento ser tan pesado.


Arduino:1.8.8 (Mac OS X), Tarjeta:"Arduino/Genuino Uno"

/Users/alvaro/Documents/Arduino/prueba_final/prueba_final.ino: In function 'void loop()':
prueba_final:33:8: error: 'motor1' was not declared in this scope
motor1() ;
^
prueba_final:37:8: error: 'motor2' was not declared in this scope
motor2();
^
prueba_final:41:8: error: 'motor3' was not declared in this scope
motor3();
^
prueba_final:45:8: error: 'motor4' was not declared in this scope
motor4();
^
/Users/alvaro/Documents/Arduino/prueba_final/prueba_final.ino: At global scope:
prueba_final:62:1: error: expected unqualified-id before '{' token
{
^
exit status 1
'motor1' was not declared in this scope

Este informe podría contener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.
  Responder
#7
#include <Servo.h>


Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

char a;
String readString;

void setup( ) {
pinMode(13,OUTPUT);
servo1.attach(8);
servo2.attach(9);
servo3.attach(10);
servo4.attach(11);
Serial.begin(9600);
servo1.write(8);
servo2.write(100);
servo3.write(164);
servo4.write(90);
delay (10);
}

void loop() {
if (Serial.available() ) {

a = Serial.read();

if (a=='A') {
motor1() ;
}

if (a=='B') {
motor2();
}

if (a=='C') {
motor3();
}

if (a=='D') {
motor4();
}

if (a=='E') {
digitalWrite(13,HIGH);
delay (10);
}

if (a=='F') {
digitalWrite(13,LOW);
delay (10);
}
}

}

void motor1()
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo1.write (readString.toInt() );
readString="";
}
}



void motor2()
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo2.write (readString.toInt() );
readString="";
}
}



void motor3()
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo3.write (readString.toInt() );
readString="";
}
}



void motor4()
{
delay (10);
while (Serial.available() ) {

char c = Serial.read();
readString += c;

}
if (readString.length() >0) {
Serial.println (readString.toInt() );
servo4.write (readString.toInt() );
readString="";
}
}


Prueba esto a ver.. No estaban bien definidas, sobraban ; que había al declarar la función.
  Responder
#8
Perfectísimo muchísimas gracias de verdad se lo agradezco.
Ahora me da problema al subirlo a la placa puff
  Responder
#9
Si el arduino está encendido y el ordenador la reconoce... Comprueba la configuración que tengas seleccionada el tipo de placa UNO y el puerto COM correcto, o como se llamen en iOS.
  Responder
#10
Es que soy tonto, muchísimas gracias, ya no molesto más.
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  DUDA arduino uno + GPS + SD + SDS011 JRRAmirez 1 0 23-07-2023, 04:57 PM
Último mensaje: asesorplaza1
  exit status 1 Error compilando para la tarjeta Arduino/Genuino Uno fcojavier 26 59,300 18-03-2022, 11:26 PM
Último mensaje: asesorplaza1
  Como leer ultima linea de la tarjeta SD? Antude 0 694 28-08-2021, 08:41 AM
Último mensaje: Antude
  CONSULTA Error compilando para la tarjeta Arduino Mega or Mega 2560. minaki24fc 2 1,094 26-03-2021, 10:45 PM
Último mensaje: asesorplaza1
  Placa MEGA(china) la reconoce como UNO Jaimelito 1 888 18-11-2020, 10:15 PM
Último mensaje: asesorplaza1