-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.cpp
53 lines (41 loc) · 969 Bytes
/
driver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "driver.h"
#include "Arduino.h"
driver::driver(int p1, int p2, int p3, int p4, int p5){
enPin = p1;
clkPin = p2;
aclkPin = p3;
pwmPin = p4;
csPin = p5;
}
void driver::init(){
pinMode(enPin, OUTPUT);
pinMode(clkPin, OUTPUT);
pinMode(aclkPin, OUTPUT);
pinMode(pwmPin, OUTPUT);
pinMode(csPin, INPUT);
digitalWrite(enPin, HIGH);
digitalWrite(clkPin, LOW);
digitalWrite(aclkPin, HIGH);
dir = 'a';
digitalWrite(pwmPin, LOW);
}
void driver::drive(int duty){
analogWrite(pwmPin, duty);
}
void driver::setDir(char d){
if(d == 'a'){
digitalWrite(clkPin, LOW);
digitalWrite(aclkPin, HIGH);
dir = 'a';
}
else if(d == 'c'){
digitalWrite(aclkPin, LOW);
digitalWrite(clkPin, HIGH);
dir = 'c';
}
}
float driver::getCurr(){
int s = analogRead(csPin);
float curr = (float)5*0.3*11370*(((float)s/1024)/1500);
return curr;
}