This code below, worked before the latest update. Now, when I try to compile it, I get errors. What is wrong with it?
/*
RC Car to Robot Conversion
by Randy Sarafan
Used to convert an RC car into a robot that uses a PING sensor to avoid obstacles,
and an Arduino motor shield for motor control.
For more information see:
http://www.instructables.com/id/RC-Car-to-Robot/
Built atop Ping example code by Tom Igoe
*/
// this constant won't change. It's the pin number
int lm1 = 8;
int lm2 = 11;
int rm1 = 12;
int rm2 = 13;
int rms = 10;
int lms = 9;
const int pingPin = 7;
void setup() {
//establish motor direction toggle pins
pinMode(8, OUTPUT); //drive motor -- HIGH = forwards and LOW = backwards
pinMode(13, OUTPUT); //turn motor -- HIGH = left and LOW = right
//establish motor brake pins
pinMode(11, OUTPUT); //brake (disable) the drive motor
pinMode(12, OUTPUT); //brake (disable) the turn motor
pinMode(10, OUTPUT);
pinMode(9, INPUT);
//Turns brake off for drive motor
//Turns brake on for turn motor
analogWrite(lms, 500);
analogWrite(rms, 500);
//Sets initial speed of drive motor
digitalWrite(lm1, HIGH);
digitalWrite(rm2, LOW);
digitalWrite(rm1, HIGH);
digitalWrite(lm2, LOW);
//Sets initial direction of drive motor
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
//
//if objects are less than 12 inches away
//the robot reverses and turns to the right
//for 2 seconds
//
if (inches < 12){
//brake drive motor and pause 1/10 second
digitalWrite(rm1, HIGH);
digitalWrite(lm1, HIGH);
delay(100);
//
//setting turn motor
//
digitalWrite(rm2, LOW);
digitalWrite(lm2, HIGH);
analogWrite(lms, 500);
analogWrite(rms, 750);
//turn off brake for turn motor
digitalWrite(rm1, HIGH);
digitalWrite(lm1, HIGH);
delay(2000);
digitalWrite(lms, 0);
digitalWrite(rms, 0);
delay(2000);
digitalWrite(lms, 1000);
digitalWrite(rms, 1000);
//set turn motor direction
}
//
//when nothing is within 12"
//the robot simply drives forwards
//
else{
analogWrite(lms, 1000);
analogWrite(rms, 1000);
digitalWrite(lm2, HIGH);
digitalWrite(rm2, HIGH);
digitalWrite(rm1, LOW);
digitalWrite(lm1, LOW);
}
}
delay(100);
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
Also, ignore the pseudo code. It is from an old modified code.