Go Down

Topic: Servo libray error message (Read 158 times) previous topic - next topic

sprocketpower

Hi,Ii am trying to build a robot that will scramble a rubix cube, at the moment, I am setting up procedures for each action then executing them in the main loop with delays betewen just to test everything, the stepper sections of coder are working fine, however when I added the servos, i got an error message when I compiled saying

""exit status 1
request for member 'attach' in 'up', which is of non-class type 'Servo()'"

i have posted my code below

Code: [Select]
//Include the Arduino Stepper Library
#include <Stepper.h>
#include <Servo.h>
 
// Define Constants

Servo up();
Servo pinch();
 
// Number of steps per internal motor revolution
const float STEPS_PER_REV = 32;
 
//  Amount of Gear Reduction
const float GEAR_RED = 64;
 
// Number of steps per geared output rotation
const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;
 
// Define Variables
 
// Number of Steps Required
int StepsRequired;
 
// Create Instance of Stepper Class
// Specify Pins used for motor coils
// The pins used are 8,9,10,11
// Connected to ULN2003 Motor Driver In1, In2, In3, In4
// Pins entered in sequence 1-3-2-4 for proper step sequencing
 
Stepper steppermotor(STEPS_PER_REV, 8, 10, 9, 11);
 
void setup()
{
 
  up.attach(5); //sets lifting servo control to pin 5
  pinch.attach(3); //sets pinching servo control to pin 5
  //(Stepper Library sets pins as outputs)
}
 
void loop()
{
  clock();

  delay(1000);
 
  clock2();

  delay(1000);

  aclock();
 
  delay(1000);
 
  aclock2();

  open();

  delay(1000);

  close();

  delay(1000);

  lift();

  delay(1000);

  drop();
}

void clock() // Clockwise 1/4 turn
{
  StepsRequired  = STEPS_PER_OUT_REV / 4;   
  steppermotor.setSpeed(700); 
  steppermotor.step(StepsRequired);
}

void clock2() // Clockwise 1/2 turn
{
  StepsRequired  = STEPS_PER_OUT_REV / 2;   
  steppermotor.setSpeed(700); 
  steppermotor.step(StepsRequired);
}

void aclock() // Anti-Clockwise 1/4 turn
{
  StepsRequired  = - STEPS_PER_OUT_REV / 4;   
  steppermotor.setSpeed(700); 
  steppermotor.step(StepsRequired);
}

void aclock2() // Anti-Clockwise 1/2 turn
{
  StepsRequired  = - STEPS_PER_OUT_REV / 2;   
  steppermotor.setSpeed(700); 
  steppermotor.step(StepsRequired);
}

void open() //Squeeze jaws
{
  pinch.write(180);
}

void close() //Release jaws
{
  pinch.write(0);
}

void lift() //Lift jaws
{
  up.write(180);
}

void drop() //Drop jaws
{
  up.write(0);
}

pert

Code: [Select]
Servo up();
Servo pinch();

Your syntax for the Servo constructor is incorrect. As shown in the Servo library example sketches, it should be like this:
Code: [Select]
Servo up;
Servo pinch;

sprocketpower

gahh, thank you. what a silly error.

pert

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per

Go Up