0

I attempted to compile this Arduino sketch with a custom library in it (jtaServoController), and the Arduino IDE claims that my constructor in the Arduino sketch was written incorrectly (more precisely, 'jtaServoControllerFour' does not name a type).

#include <jtaServoController.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);

#define SERVOMIN  0
#define SERVOMAX  600

jtaServoControllerFour pointerFinger(1,2,3,4);   //line in question


void setup() {
  Serial.begin(9600);
  pwm1.begin();
  pwm1.setPWMFreq(60);
}

void loop() {
  pointerFinger.jtaSetPWMFour(300,400,500,600);
}

My Question is whether the line in question actually is written wrong or is there an issue in another part of my code?-probably in the library itself which I have below. (btw I found the information for constructing an object in the Arduino tutorial on libraries).

These are the Header and .cpp files respectively:

#ifndef jtaServoController_h
#define jtaServoController_h

#include "Wire.h"
#include "Adafruit_PWMServoDriver.h"
#include "Arduino.h"

class jtaServoControllerFour
{
    public:
        jtaServoControllerFour(int servo1, int servo2, int servo3, int servo4);
        void jtaSetPWMFour(unsigned int servo41, unsigned int servo42, unsigned int servo43, unsigned int servo44);
    private:
        int _servoOne;
        int _servoTwo;
        int _servoThree;
        int _servoFour;
};


   #endif

CPP file

#include "Arduino.h"
#include "jtaServoController.h"
#include "Adafruit_PWMServoDriver.h"
#include "Wire.h"

jtaServoControllerFour::jtaServoControllerFour(int servoOne, int servoTwo, int servoThree, int servoFour)
{
    _servoOne = servoOne;
    _servoTwo = servoTwo;
    _servoThree = servoThree;
    _servoFour = servoFour;
}

void jtaServoControllerFour::jtaSetPWMFour(int servoFourOne, int servoFourTwo, int servoFourThree, int servoFourFour)
{
    pwm1.setPWM(_servo1, 0, servoFourOne);
    pwm1.setPWM(_servo2, 0, servoFourTwo);
    pwm1.setPWM(_servo3, 0, servoFourThree);
    pwm1.setPWM(_servo4, 0, servoFourFour);
    return;
}

1 Answer 1

0
#include <jtaServoController.h>

You may need to use the following instead (double quotes):

#include "jtaServoController.h"

And/or check the path to your header file.

See here for the difference between the two.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.