Pessoal, ao tentar compilar o programa abaixo ocorreu a seguinte falha:

“Erro compilando para a placa Arduino/Genuino Uno”

 

Geralmente isso se dá por desatualização da biblioteca, assim, instalei o Adafruit MotorShield.h que era o único que faltava mas não resolveu. Alguém poderia, por favor, testar este programa, para auxiliar-me na solução desse problema?

 

#include <AFMotor.h>

// Example6 code for Brian Schmalz's Easy Driver Example page

// http://www.schmalzhaus.com/EasyDriver/EasyDriverExamples.html

#include <AccelStepper.h>

#include <Wire.h>

#include <Adafruit_MotorShield.h>

 

// Define the stepper and the pins it will use

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *motor1 = AFMS.getStepper(200, 1);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!

 

void forwardstep() { 

  motor1->onestep(FORWARD, SINGLE);

}

void backwardstep() { 

  motor1->onestep(BACKWARD, SINGLE);

}

 

AccelStepper stepper1(forwardstep, backwardstep); // use functions to step

 

// Define our three input button pins

#define  LEFT_PIN  2

#define  STOP_PIN  3

#define  RIGHT_PIN 4

// Define our analog pot input pin

#define  SPEED_PIN A0

 

// Define our maximum and minimum speed in steps per second (scale pot to these)

#define  MAX_SPEED 500

#define  MIN_SPEED 0.1

 

void setup() {

  AFMS.begin();

    // The only AccelStepper value we have to set here is the max speeed, which is higher than we'll ever go

  stepper1.setMaxSpeed(500.0);

    // Set up the three button inputs, with pullups

 

 pinMode(LEFT_PIN, INPUT_PULLUP);

  pinMode(STOP_PIN, INPUT_PULLUP);

  pinMode(RIGHT_PIN, INPUT_PULLUP);

}

void loop() {

  static float current_speed = 0.0;         // Holds current motor speed in steps/second

  static int analog_read_counter = 1000;    // Counts down to 0 to fire analog read

  static char sign = 0;                     // Holds -1, 1 or 0 to turn the motor on/off and control direction

  static int analog_value = 0;              // Holds raw analog value.

    // If a switch is pushed down (low), set the sign value appropriately

  if (digitalRead(LEFT_PIN) == 0) {

    sign = 1;

  }

  if (digitalRead(RIGHT_PIN) == 0) {   

    sign = -1;

  }

  if (digitalRead(STOP_PIN) == 0) {

    sign = 0;

  }

  // We only want to read the pot every so often (because it takes a long time we don't

  // want to do it every time through the main loop). 

  if (analog_read_counter > 0) {

    analog_read_counter--;

  }

  else {

    analog_read_counter = 3000;

    // Now read the pot (from 0 to 1023)

    analog_value = analogRead(SPEED_PIN);

    // Give the stepper a chance to step if it needs to

    stepper1.runSpeed();

    //  And scale the pot's value from min to max speeds

    current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;

    // Update the stepper to run at this new speed

    stepper1.setSpeed(current_speed);

  }

 

  // This will run the stepper at a constant speed

  stepper1.runSpeed();

}

Exibições: 2372

Responder esta

Respostas a este tópico

Copie a mensagem de erro detalhada e envie para nós.

Caro José Gustavo, eis as mensagens de erro:

 

Easy_09.ino:8:34: warning: Adafruit_MotorShield.h: No such file or directory

Easy_09:11: error: 'Adafruit_MotorShield' does not name a type

Easy_09:12: error: expected constructor, destructor, or type conversion before '*' token

Easy_09.ino: In function 'void forwardstep()':

Easy_09:17: error: 'motor1' was not declared in this scope

Easy_09.ino: In function 'void backwardstep()':

Easy_09:20: error: 'motor1' was not declared in this scope

Easy_09.ino: In function 'void setup()':

Easy_09:38: error: 'AFMS' was not declared in this scope

Oi MPF, boa noite.

Foi deste link  que baixou a biblioteca?

https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/ins...

Baixei deste link e instalei.

Ai deu erro, ai tentei compilar um code do exemplo e funcionou.

Então comentei esta linha:   #include <AFMotor.h>  do seu code  : // #include <AFMotor.h>,

e  então compilou sem erro.

A biblioteca deste link:

 https://learn.adafruit.com/adafruit-motor-shield/library-install

é diferente da biblioteca deste link

https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/ins...

Rui

Caro Rui,

Baixei-o do primeiro link, no entanto, tentei, também, o segundo que você indicou: não deu certo; continua o mesmo erro acima enviado ao José Gustavo. O que estou a fazer de errado?

Rui sua ajuda, via sala principal, foi decisiva: resolvi o problema: era, realmente, biblioteca fora de lugar. obrigado a todos.

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço