-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobatt.cpp
More file actions
63 lines (54 loc) · 920 Bytes
/
Robatt.cpp
File metadata and controls
63 lines (54 loc) · 920 Bytes
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
54
55
56
57
58
59
60
61
62
63
/*
Robatt.cpp
Library provides simple functions to control motors.
Created by Joseph Birks, 21 Oct 2013.
This code is public domain.
*/
#include "Arduino.h"
#include "Robatt.h"
RobattMotor::RobattMotor(char num)
{
if(num==1)
{
a = MOTOR1A_PIN;
b = MOTOR1B_PIN;
}
else
{
a = MOTOR2A_PIN;
b = MOTOR2B_PIN;
}
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
halt();
}
void RobattMotor::forward()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
}
void RobattMotor::off()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
}
void RobattMotor::halt()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
}
void RobattMotor::reverse()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
}
void RobattMotor::forward(unsigned char duty)
{
analogWrite(a, duty);
digitalWrite(b, LOW);
}
void RobattMotor::reverse(unsigned char duty)
{
digitalWrite(a, LOW);
analogWrite(b, duty);
}