comparison sea/sea.ino @ 0:fe0a2f223e10

Initial commit of split brain code for the Sea Dragon.
author Daniel O'Connor <darius@dons.net.au>
date Sat, 11 Jul 2015 15:20:05 +0930
parents
children 6f1cd84f8e23
comparison
equal deleted inserted replaced
-1:000000000000 0:fe0a2f223e10
1 #include <Wire.h>
2 #include <Adafruit_MotorShield.h>
3 #include "utility/Adafruit_PWMServoDriver.h"
4
5 // Orange - Vertical M2+
6 // White/orange - Vertical M2-
7 // Green - Left M3+
8 // White/green - Left M3-
9 // Blue - Right M1+
10 // White/blue - Right M1-
11 // Brown - RS485 B
12 // Brown/white - RS485 A
13
14 // Motor shield object at default address
15 Adafruit_MotorShield AFMS = Adafruit_MotorShield();
16
17 // Motor objects
18 Adafruit_DCMotor *leftMotor = AFMS.getMotor(3);
19 Adafruit_DCMotor *rightMotor = AFMS.getMotor(1);
20 Adafruit_DCMotor *vertMotor = AFMS.getMotor(2);
21
22 void setup() {
23 Serial.begin(115200);
24
25 AFMS.begin(); // Start at default frequency
26 }
27
28 int
29 parseIn(char dir) {
30 int tmp;
31
32 while (Serial.read() != dir)
33 ;
34 while (Serial.read() != ':')
35 ;
36 tmp = Serial.parseInt();
37
38 return tmp;
39 }
40
41 void loop() {
42 int tmp;
43
44 Serial.println("Parsing L...");
45 tmp = parseIn('L');
46 if (tmp > 0)
47 leftMotor->run(FORWARD);
48 else
49 leftMotor->run(BACKWARD);
50 leftMotor->setSpeed(abs(tmp));
51
52 Serial.println("Parsing R...");
53 tmp = parseIn('R');
54 if (tmp > 0)
55 rightMotor->run(FORWARD);
56 else
57 rightMotor->run(BACKWARD);
58 rightMotor->setSpeed(abs(tmp));
59
60 Serial.println("Parsing V...");
61 tmp = parseIn('V');
62 if (tmp > 0)
63 vertMotor->run(FORWARD);
64 else
65 vertMotor->run(BACKWARD);
66 vertMotor->setSpeed(abs(tmp));
67
68 Serial.println("Done");
69 }
70
71 /*
72 * Local variables:
73 * mode: c++
74 * End:
75 */