expected initializer before 'moter1'?????

why does this not work?

Code_For_Car:24:9: error: expected initializer before 'moter1'
 DCMoter moter1(11, 10);
         ^~~~~~

P.S. Sorry if this is really dumb question but I'm new sooooo...

Full Code:

class DCMoter {
  private:
    
    byte inputPin;
    
    byte outputPin;
  
  public:
    
    DCMoter(byte inputPin, byte outputPin) {
      this->inputPin = inputPin;
      this->outputPin = outputPin;

      pinMode(inputPin, INPUT);
      pinMode(outputPin, OUTPUT);
    }
    
   void Spin(byte Volts) {
      analogWrite(inputPin, Volts);
   }
}

DCMoter moter1(11, 10);

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:

  Moter1.Spin(255)
}

Full Output:

Code_For_Car:24:9: error: expected initializer before 'moter1'
 DCMoter moter1(11, 10);
         ^~~~~~
/home/errorbot1122-the-seccond/Arduino/Code_For_Car/Code_For_Car.ino: In function 'void loop()':
Code_For_Car:33:3: error: 'Moter1' was not declared in this scope
   Moter1.Spin(255)
   ^~~~~~
/home/errorbot1122-the-seccond/Arduino/Code_For_Car/Code_For_Car.ino:33:3: note: suggested alternative: 'DCMoter'
   Moter1.Spin(255)
   ^~~~~~
   DCMoter
exit status 1
expected initializer before 'moter1'
  1. You need a ; after your the closing bracket of you class definition.
  2. Capitalize your instance to be consistent with the use in the code
  3. add a missing ; after Motor1.spin(255)
  4. Pay attention to details :wink:
class DCMoter {
  private:
    
    byte inputPin;
    
    byte outputPin;
  
  public:
    
    DCMoter(byte inputPin, byte outputPin) {
      this->inputPin = inputPin;
      this->outputPin = outputPin;

      pinMode(inputPin, INPUT);
      pinMode(outputPin, OUTPUT);
    }
    
   void Spin(byte Volts) {
      analogWrite(inputPin, Volts);
   }
};//add ;

//DCMoter moter1(11, 10);
DCMoter Moter1(11, 10);//capitalize

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:

  Moter1.Spin(255);//add ;
}

thank you!!!! it should work now :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.