I auto-formatted your code - hopefully this makes things clearer.
#include <Wire.h>
#include <Servo.h> //includes the servo library to PWM the servo
#include <Time.h> //??
unsigned long time = millis();
int HMC6352Address = 0x42;
// This is calculated in the setup() function
int slaveAddress;
int ledPin = 13;
boolean ledState = false;
byte headingData[2];
int i, headingValue;
const int ENA = 9;
const int IN1 = 12;
const int IN2 = 13;
//servo control?
Servo Steering; //defines the servo to be used to steer?
int depthValue;
const int left = 135;
const int right = 45;
const int straight = 90;
void setup()
{
// Shift the device's documented slave address (0x42) 1 bit right
// This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
slaveAddress = HMC6352Address >> 1; // This results in 0x21 as the address to pass to TWI
Serial.begin(9600);
Wire.begin();
pinMode(ENA, OUTPUT); // only controls one motor - Hbridge could do 2...
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
Depth.attach(11);
Steering.attach(10); //attaches the steering servo to pin 10
}
void loop()
{
// Send a "A" command to the HMC6352
// This requests the current heading data
Wire.beginTransmission(slaveAddress);
Wire.write("A"); // The "Get Data" command
Wire.endTransmission();
delay(10); // The HMC6352 needs at least a 70us (microsecond) delay
// after this command. Using 10ms just makes it safe
// Read the 2 heading bytes, MSB first
// The resulting 16bit word is the compass heading in 10th's of a degree
// For example: a heading of 1345 would be 134.5 degrees
Wire.requestFrom(slaveAddress, 2); // Request the 2 byte heading (MSB comes first)
i = 0;
while(Wire.available() && i < 2)
{
headingData[i] = Wire.read();
i++;
}
headingValue = headingData[0]*256 + headingData[1]; // Put the MSB and LSB together
Serial.print("Current heading: ");
Serial.print(int (headingValue / 10)); // The whole number part of the heading
Serial.print(".");
Serial.print(int (headingValue % 10)); // The fractional part of the heading
Serial.println(" degrees");
delay(500);
delay(10);
//MOTOR CONTROL as taken from somewhere and butchered
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW); // GO!
//my attempts at driving this thing
if (time < 10000){ //for first ten seconds, go east
if(headingValue/10 >= 95 && headingValue/10 <= 270)
Steering.write(left);
if (headingValue/10 <= 85 || headingValue/10 > 270)
Steering.write(right);
if (headingValue/10 >85 && headingValue/10 <95)
Steering.write(straight);
}
delay(10);
//turn around (west) and keep running home
if(time >= 10000){
if(headingValue/10 >= 275 || headingValue/10 <= 90)
Steering.write(left);
if (headingValue/10 <= 265 && headingValue/10 > 90)
Steering.write(right);
if (headingValue/10 >265 && headingValue/10 <275)
Steering.write(straight);
}
delay (10);
}