conversion from 'mole*' to non-scalar type 'mole' requested

why must you error >:(

plz help me <3

main.ino file

#include <mole.h>

mole mole1 = new mole( 2, 8  );
mole mole2 = new mole( 3, 9  );
mole mole3 = new mole( 4, 10 );
mole mole4 = new mole( 5, 11 );
mole mole5 = new mole( 6, 12 );
mole mole6 = new mole( 7, 13 );

//I would also like a array of moles here so I can do something like this.
//moleArray[0].sould_be_up = true;
void setup() {
  // put your setup code here, to run once:
}

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

mole.cpp file

#include "Arduino.h"
#include "mole.h"

mole::mole(int po, int pi) {
  pinMode(po , OUTPUT);
  pinMode(pi , INPUT );
  _pino = po;
  _pini = pi;
}

void mole::changeMoleSate() {
  if (sould_be_up == false) {
    digitalWrite(_pino, LOW);
  }
  else {
    digitalWrite(_pini, HIGH);
  }
}

void mole::resetMole() {
  sould_be_up = false;
  _up_timer = 0;
  _recovery_timer = 0;
  digitalWrite(_pino, LOW);
}


void mole::setUpTimer(int up_timer) {
  _up_timer = up_timer;
}

int mole::getUpTimer() {
  return _up_timer;
}

void mole::decrementUpTimer() {
  if (_up_timer > 0) {
    _up_timer--;
  }
}


void mole::setRecoveryTimer(int recovery_timer) {
  _recovery_timer += recovery_timer;
}

int mole::getRecoveryTimer() {
  return _recovery_timer;
}

void mole::decrementRecoveryTimer() {
  if (_recovery_timer > 0) {
    _recovery_timer--;
  }
}

mole.h file

#ifndef mole_h
#define mole_h

#include "Arduino.h"

class mole
{
  public:
    mole(int po, int pi);
    void changeMoleSate();
    void resetMole();

    void setUpTimer(int up_timer);
    int  getUpTimer();
    void decrementUpTimer();

    void setRecoveryTimer(int recovery_timer);
    int  getRecoveryTimer();
    void decrementRecoveryTimer();

    boolean sould_be_up = false;

  private:
    int _up_timer = 0;
    int _recovery_timer = 0;
    int _pino;
    int _pini;
};
#endif

Hi,
Is this to do with this thread?
http://forum.arduino.cc/index.php?topic=429340.msg2959817#msg2959817

Just dumping code at the start of a thread with no explanation of what it is supposed to do and what it does, will not get you any reasonable answers.

Where did you get the library, mole.
What IDE version are you using?
What model Arduino are you using?

Thanks.. Tom... :slight_smile:

mole mole1 = new mole( 2, 8  );"new" returns a . . . what?

mole::mole(int po, int pi) {
  pinMode(po , OUTPUT);
  pinMode(pi , INPUT );

When your constructor is called, the hardware is not ready to be diddled with, so quit diddling with the hardware in the constructor.

Try:

mole mole1( 2, 8  );
mole mole2( 3, 9  );
mole mole3( 4, 10 );
mole mole4( 5, 11 );
mole mole5( 6, 12 );
mole mole6( 7, 13 );

PaulS:

mole::mole(int po, int pi) {

pinMode(po , OUTPUT);
  pinMode(pi , INPUT );



When your constructor is called, the hardware is not ready to be diddled with, so quit diddling with the hardware in the constructor.

Put another way the only thing you can do in a constructor that is called from top-level is set the value of
variables. Top level expressions happen first as the program is initialized, so no machinery from the
Arduino environment is guaranteed to work, not even new I think.

@TomGeorge

Where did you get the library mole? I made it ╭∩╮(-_-)╭∩╮,I did not want it to be a library I just wanted it to be a class that I can make instances of.
What IDE version are you using? 1.6.12
What model Arduino are you using? should not madder but the Arduino/Genuino Uno chip mega328u

and your like is down bro help me understand where i went wrong in my program (this is whakamole) - Programming Questions - Arduino Forum

the code worked just fined until I added second argument to the constructor.

@PaulS
my code

mole::mole(int po, int pi) {
  pinMode(po , OUTPUT);
  pinMode(pi , INPUT );
}

the example on library's even shows setting a pin to be a output in the constructor??

their code

Morse::Morse(int pin)
{
  pinMode(pin, OUTPUT);
  _pin = pin;
}

is just you cant set a pin to be a input??

@MarkT
THANKS!! FOR THE HELP

Arduino environment is guaranteed to work, not even new I think.

The new operator is NOT specific to the Arduino or hardware-related, so, of course it will work.