-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotorstest.ino
81 lines (65 loc) · 1.68 KB
/
motorstest.ino
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//motor A connected between A01 and A02
//motor B connected between B01 and B02
int STBY = 12; //standby
//Motor A
int PWMA = 13; //Speed control
int AIN1 = 14; //Direction
int AIN2 = 15; //Direction
// //Motor B
// int PWMB = 5; //Speed control
// int BIN1 = 11; //Direction
// int BIN2 = 12; //Direction
void setup(){
Serial.begin(115200);
Serial.println("Starting...");
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
// pinMode(PWMB, OUTPUT);
// pinMode(BIN1, OUTPUT);
// pinMode(BIN2, OUTPUT);
}
void loop(){
move(1, 100, 1); //motor 1, full speed, left
// move(2, 255, 1); //motor 2, full speed, left
delay(1000); //go for 1 second
// stop(); //stop
// delay(250); //hold for 250ms until move again
// move(1, 100, 0); //motor 1, half speed, right
// // move(2, 128, 0); //motor 2, half speed, right
// delay(1000);
// stop();
// delay(250);
}
void move(int motor, int speed, int direction) {
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
Serial.print("Setting Motor");
Serial.print(motor);
Serial.print(" to ");
Serial.println(speed);
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}
if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}
// else{
// digitalWrite(BIN1, inPin1);
// digitalWrite(BIN2, inPin2);
// analogWrite(PWMB, speed);
// }
}
void stop(){
//enable standby
digitalWrite(STBY, LOW);
}