Hello, i have Arduino robot wich has a compass. i make selfparking car with 4 IR sensors but i want to use the compass with parking. so i can read the value from compass but I want to stop the robot after it has driven 45 degrees. but i can't know how i programm that. i wrote simple code to understand what i want.
// include the robot library
#include <ArduinoRobot.h>
#include <Wire.h>
int compassValue;
int direc = 180;
void setup() {
Robot.begin();
}
void loop() {
Robot.motorsWrite(-100, -50); // Robot goes back with 45 degrees
// read the compass orientation
compassValue = Robot.compassRead();
// mybe its 90 or 180 that depends on the direction
// how many degrees are we off
int diff = direc - compassValue;
if( diff == 45)
{
Robot.motorsStop();
}
}