Hi,
I'm in the process of writing my first library, I need to use software serial but i keep getting an error when ever I do, what is it I'm doing wrong.
The library is for the motor controller from web4robot
any ways heres the code followed by the error, hope some one can help.
Motor.cpp
#include "WProgram.h"
#include "Motor.h"
#include "SoftwareSerial.h"
Motor::Motor(int rx,int tx)
{
mySerial = SoftwareSerial(rx,tx);
pinMode(rx, OUTPUT);
pinMode(tx, OUTPUT);
mySerial.begin(9600);
}
void Motor::motor1Stop(){motorComand(1,1,0x00);}
void Motor::motor2Stop(){motorComand(2,1,0x00);}
void Motor::motor1Forwards(char mSpeed){motorComand(1,1,mSpeed);}
void Motor::motor1Backwards(char mSpeed){motorComand(1,2,mSpeed);}
void Motor::motor2Forwards(char mSpeed){motorComand(2,1,mSpeed);}
void Motor::motor2Backwards(char mSpeed){motorComand(2,2,mSpeed);}
void Motor::motorComand(int motor, int mDirection, char mSpeed){
char buff[5];
buff[0]=254; // Start byte
buff[1]=77; // Device ID
buff[2]=0x03; // Comand (03 = Motor Speed)
if(motor <= 1){
if(mDirection <= 1){
buff[3]=0x00; // Motor and Direction (00 = Motor 1 Forwards, 01 = Motor 1 Bacwards, 02 = Motor 2 Forwards, 03 = Motor 2 Bacwards,
}
else{
buff[3]=0x01; // Motor and Direction (00 = Motor 1 Forwards, 01 = Motor 1 Bacwards, 02 = Motor 2 Forwards, 03 = Motor 2 Bacwards,
}
}
else{
if(mDirection <= 1){
buff[3]=0x02; // Motor and Direction (00 = Motor 1 Forwards, 01 = Motor 1 Bacwards, 02 = Motor 2 Forwards, 03 = Motor 2 Bacwards,
}
else{
buff[3]=0x03; // Motor and Direction (00 = Motor 1 Forwards, 01 = Motor 1 Bacwards, 02 = Motor 2 Forwards, 03 = Motor 2 Bacwards,
}
}
buff[4]=mSpeed; // Speed
for(int i=0;i<5;i++){mySerial.print(buff[i],BYTE);}
}
Motor.h
#ifndef Motor_h
#define Motor_h
#include "WProgram.h"
#include "SoftwareSerial.h"
class Motor
{
public:
Motor(int rx,int tx);
void motor1Stop();
void motor2Stop();
void motor1Forwards(char mSpeed);
void motor1Backwards(char mSpeed);
void motor2Forwards(char mSpeed);
void motor2Backwards(char mSpeed);
private:
void motorComand(int motor, int mDirection, char mSpeed);
SoftwareSerial mySerial;
};
#endif
Error
Motor.cpp: In constructor 'Motor::Motor(int, int)':
Motor.cpp:11: error: no matching function for call to 'SoftwareSerial::SoftwareSerial()'
hardware\libraries\SoftwareSerial/SoftwareSerial.h:34: note: candidates are: SoftwareSerial::SoftwareSerial(uint8_t, uint8_t)
hardware\libraries\SoftwareSerial/SoftwareSerial.h:26: note: SoftwareSerial::SoftwareSerial(const SoftwareSerial&)