-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathz02-motor-testing
75 lines (48 loc) · 1.83 KB
/
z02-motor-testing
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
// RC Car servo and big motor driver
// By Jeremy Ellis
// MIT license
// for now reference at https://github.com/hpssjellis/particle.io-photon-high-school-robotics/tree/master/a11-dc-motor-drivers
// although pin names wrong
// You are suppossed to get it working using the web-app
// Draw your circuit diagram first
// This program will just tell you if the connections are working
// See https://www.pololu.com/product/1451 for assistance
// On motor driver board LED goes red for one direction and green for the other
#include <Arduino.h> // Only needed by https://platformio.org/
#include <Servo.h>
Servo myServo_D2;
void setup() {
myServo_D2.attach(D2); // D2 should do PWM on Portenta
pinMode(D3, OUTPUT); // digital 0 to 1
pinMode(D5, OUTPUT); // PWM 0 to 255
pinMode(D6, OUTPUT); // digital 0 to 1
// both off = glide, both on = brake (if motor can do that)
digitalWrite(D5, 1); // set one direction
digitalWrite(D3, 0); // set one direction
pinMode(LEDB, OUTPUT);
// to connect wires and put car on ground
digitalWrite(LEDB, LOW); // D7 on
delay(15000);
digitalWrite(LEDB, HIGH); // D7 on
delay(2000);
}
void loop() {
digitalWrite(LEDB, LOW); // D7 on
myServo_D2.write(110); // turn
analogWrite(D4, 50); // go medium
delay(300);
analogWrite(D4, 0); // stop
delay(3000);
myServo_D2.write(70); // turn
analogWrite(D4, 50); // go medium
delay(300);
analogWrite(D4, 0); // stop
delay(3000);
myServo_D2.write(90); // go straight
analogWrite(D4, 50); // go medium
delay(300);
analogWrite(D4, 0); // stop
delay(3000);
digitalWrite(LEDB, HIGH); // D7 off
delay(9000); // wait 9 seconds
}