Go Down

Topic: Error in class definition (Read 2787 times) previous topic - next topic

Teacup

Mar 18, 2012, 07:39 am Last Edit: Mar 18, 2012, 07:51 am by Teacup Reason: 1
Heya,

I just started using an old Arduino Decimila that my friend leant to me.  I am trying to remember some of my old programing but for the life of me can't figure out why this class definition isn't working.  I was wondering if someone could help?

The code and the error message are bellow.  Any ideas?

Cheers,
David

ERROR:
Quote
sketch_mar18a:66: error: expected `}' at end of input
sketch_mar18a.cpp: In member function 'int Leg::getS0()':
sketch_mar18a:18: error: expected primary-expression before ')' token
sketch_mar18a:18: error: expected `;' before ')' token
sketch_mar18a:66: error: expected `}' at end of input
sketch_mar18a.cpp: At global scope:
sketch_mar18a:66: error: expected unqualified-id at end of input


CODE:
Quote
#include <Servo.h>

class Leg
{
 private:
 int s0;
 int s1;
 int d0;
 int d1;
 
 Leg() {};
 
 public:
 Leg(int inputS0, int inputS1);
 
 void setS0(int inputS0);
 void setS1(int inputS1);
 
 int getS0() {return s0;)  
 int getS1() {return s1;)
 int getD0() {return d0;)
 int getD1() {return d1;)
};

Leg::Leg(int inputS0, int inputS10)
{
 d0 = 138;
 d1 = 58;
 setS0(inputS0);
 setS1(inputS1);

void Leg::setS0(int inputS0)
{
 if (inputS0 > 180) inputS0 = 180;
 if (inputS0 < 0) inputS0 = 0;
 s0 = inputS0;
}

void Leg:setS1(int inputS1)
{
 if (inputS1 > 135) inputS1 = 135;
 if (inputS1 < 0) inputS1 = 0;
 s1 = inputS1;
}


Servo servo0;
Servo servo1;
int lowerLimit = 540; // 0 degrees at 540 microsecs with 0 degs tollerance
int upperLimit = 2360; //180 degrees at 2360 microsecs with 0 degs tollerance

Leg leg0;

void setup()
{
 servo0.attach(0,lowerLimit, upperLimit);
 servo1.attach(1,lowerLimit, upperLimit);
}

void loop()
{
 leg0.setS0(0);
 leg0.setS1(0);
 servo0.write(getS0());
 servo1.write(180 - getS1());
 delay(1000);
}

dxw00d

Quote
int getS0() {return s0;) 
  int getS1() {return s1;)
  int getD0() {return d0;)
  int getD1() {return d1;)


Open brace, close parenthesis?

PaulS

Code: [Select]
  Leg() {};
Your no-argument constructor does not set any of the member variables. Why not? Why do you have a no-argument constructor?

lefstin

Code: [Select]
void Leg:setS1(int inputS1)

Missing a colon I think.

Teacup

Thank you very much guys!  This helped a lot, there were a couple of other bugs too I am embarassed to say, but after the parentheses problem was fixed the rest were easy spot.

Thanks guys!

David

Go Up