I'm having trouble with some code, I was hoping someone else could take a look and tell me where I went wrong:
int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface
int pinI4=13;//define I4 interface
int speedpinB=10;//enable motor B
int speed =127;//define the spead of motor
const int pingPin=7;//defines pin number of sensor's output. let it be noted that const means constant
void setup()
{
Serial.begin(9600); //initializes serial communication
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
}
void forward()
{
analogWrite(speedpinA,speed);//input a simulation value to set the speed
analogWrite(speedpinB,speed);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,HIGH);
digitalWrite(pinI1,LOW);
}
void backward()//
{
analogWrite(speedpinA,speed);//input a simulation value to set the speed
analogWrite(speedpinB,speed);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
}
void left()//
{
analogWrite(speedpinA,speed);//input a simulation value to set the speed
analogWrite(speedpinB,speed/2);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void stop()//
{
digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor.
digitalWrite(speedpinB,LOW);
delay(1000);
}
void Sensor_loop()//this function is going to need to be played with_OLD NOTE
{
long duration, inches;//establishes variables: duration and distance(inches)
//the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends 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);
pinMode(pingPin, INPUT);
duration=pulseIn(pingPin, HIGH);
//code to convert time to distance
inches=microsecondsToInches(duration);
Serial.print(inches);
Serial.print("in, ");
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds/74/2;
}
void loop()//Main program
{
Sensor_loop();
delay(100);
stop();
if(inches>6)
{
forward();
delay(2000);
stop();
}
else
{
backward();
delay(2000);
stop();
left();
delay(2000);
stop();
}
}
The compiler is reporting an issue in the "void loop" function. And claims that "inches" is not declared.
Any help would be awesome. I'm hoping to get this up and running before I leave for Basic on Sunday!