0

I am making a basic library to control some stepper motors and have button input using analogread.

I am getting 6 errors and 2 warning all with my class that gets included. I think my problem lies with the class itself and the header file.

AnalogButtons.cpp

#include <Arduino.h>
#include "AnalogButtons.h"

AnalogButtons::AnalogButtons(int pin, int *btns){
    m_pin = pin;
    *m_btns = *btns;
}

int AnalogButtons::check() {
    int ch = analogRead(m_pin);
    for(size_t i=0; i<sizeof(m_btns); i++){
        if(m_btns[i] - m_buff <= ch
            && m_btns[i] + m_buff){
                return i;
            }
    }
    return -1;
}

No errors.

AnalogButtons.h

#ifndef ANALOGBUTTONS_H
#define ANALOGBUTTONS_H

class AnalogButtons {  // <--
private:
    int m_pin;
    int m_btns[5];
    int m_buff = 50;

public:
    AnalogButtons(int pin, int *btns);  // <--

    int check();
};

#endif

Errors:

Error   GCC constexpr AnalogButtons::AnalogButtons(const AnalogButtons&)    4:7
Error   GCC candidate expects 1 argument, 0 provided    4:7
Error   GCC constexpr AnalogButtons::AnalogButtons(AnalogButtons&&) 4:7
Error   GCC AnalogButtons::AnalogButtons(int, int*) 11:5
Error   GCC initializing argument 2 of 'AnalogButtons::AnalogButtons(int, int*)'    11:5
Error   GCC candidate expects 2 arguments, 0 provided   11:5

Stepper.cpp

#include <Arduino.h>
#include "AnalogButtons.h"

class Stepper {
private:
    int m_count = 0; // 1/8 step
    int m_step;
    int m_dir;
    int m_enable;
    int m_ms1;
    int m_ms2;
    bool m_ms = false;
    AnalogButtons m_ab;

public:
    Stepper(int step, int dir, int enable, int btnPin, int *btns) { // <--
        m_step = step;
        m_dir = dir;
        m_enable = enable;
        m_ab = AnalogButtons(btnPin, *btns); // <--
    }
    Stepper(int step, int dir, int enable, int btnPin, int *btns, int  ms1, int ms2) { // <--
        m_ms = true;
        m_step = step;
        m_dir = dir;
        m_enable = enable;
        m_ab = AnalogButtons(btnPin, *btns); // <--
        m_ms1 = ms1;
        m_ms2 = ms2;
    }

    int forward() {
        return forward(1);
    }
    int forward(int steps) {
        return m_count;
    }

    int backward() {
        return backward(1);

    }
    int backward(int steps) {
        return m_count;
    }
};

Errors:

Error   GCC no matching function for call to 'AnalogButtons::AnalogButtons()'   16:67
Error   GCC candidates are: 16:67
Error   Build   error: no matching function for call to 'AnalogButtons::AnalogButtons()'   16:67
Error   GCC no matching function for call to 'AnalogButtons::AnalogButtons()'   22:85
Error   GCC candidates are: 22:85
Error   Build   error: no matching function for call to 'AnalogButtons::AnalogButtons()'   22:85
Warning GCC invalid conversion from 'int' to 'int*' [-fpermissive]  20:43
Warning GCC invalid conversion from 'int' to 'int*' [-fpermissive]  27:43

I have no idea why these errors are here or how to fix them.

Drew
  • 1,171
  • 4
  • 21
  • 36

0 Answers0