You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.6 KiB
92 lines
1.6 KiB
5 years ago
|
#ifndef _MOTORZ_H // not #ifnotdef
|
||
|
#define _MOTORZ_H
|
||
|
|
||
|
class Motorz
|
||
|
{
|
||
|
private:
|
||
|
int motor_speed=0;
|
||
|
int enable,in1,in2,dir;
|
||
|
public:
|
||
|
|
||
|
Motorz(int Enb,int ina,int inb){
|
||
|
enable=Enb;
|
||
|
in1=ina;
|
||
|
in2=inb;
|
||
|
pinMode(enable,OUTPUT);
|
||
|
pinMode(in1,OUTPUT);
|
||
|
pinMode(in2,OUTPUT);
|
||
|
}
|
||
|
Motorz(int Enb,int ina,int inb,int d){
|
||
|
enable=Enb;
|
||
|
in1=ina;
|
||
|
in2=inb;
|
||
|
dir=d;
|
||
|
pinMode(enable,OUTPUT);
|
||
|
pinMode(in1,OUTPUT);
|
||
|
pinMode(in2,OUTPUT);
|
||
|
Direction();
|
||
|
}
|
||
|
void SetSpeed(int Mspeed){
|
||
|
motor_speed=Mspeed;
|
||
|
}
|
||
|
int GetSpeed(){
|
||
|
return motor_speed;
|
||
|
}
|
||
|
void SetEnable(int pin){
|
||
|
enable=pin;
|
||
|
}
|
||
|
int GetEnable(){
|
||
|
return enable;
|
||
|
}
|
||
|
void SetInput1(int pin){
|
||
|
in1=pin;
|
||
|
}
|
||
|
int GetInput1(){
|
||
|
return in1;
|
||
|
}
|
||
|
void SetInput2(int pin){
|
||
|
in2=pin;
|
||
|
}
|
||
|
int GetInput2(){
|
||
|
return in2;
|
||
|
}
|
||
|
void SetDirection(int a){
|
||
|
dir=a;
|
||
|
}
|
||
|
int GetDirection(){
|
||
|
return dir;
|
||
|
}
|
||
|
void ChangeDir(){
|
||
|
if(dir==0){
|
||
|
dir=1;
|
||
|
}
|
||
|
else{
|
||
|
dir=0;
|
||
|
}
|
||
|
}
|
||
|
void Start(){
|
||
|
this->Direction();
|
||
|
analogWrite(enable,motor_speed);
|
||
|
}
|
||
|
void Stop(){
|
||
|
this->Halt();
|
||
|
}
|
||
|
private:
|
||
|
void Direction(){
|
||
|
if(dir==0){
|
||
|
digitalWrite(in1,HIGH);
|
||
|
digitalWrite(in2,LOW);
|
||
|
}
|
||
|
else{
|
||
|
digitalWrite(in1,LOW);
|
||
|
digitalWrite(in2,HIGH);
|
||
|
}
|
||
|
}
|
||
|
void Halt(){
|
||
|
digitalWrite(in1,LOW);
|
||
|
digitalWrite(in2,LOW);
|
||
|
}
|
||
|
|
||
|
};
|
||
|
#endif _MOTOR_H
|