ok i re wrote a few things see what you think heres the new code.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
const int pingPin = 8; //ping sensor pin number
int pos = 90; // variable to set the initial position of the servo
const int ping = 8; //ping pin number
int reset = 2;// motordriver reset pin number
void setup()
{
Serial.begin(9600); //sets serial communication bps
pinMode (reset, OUTPUT);
digitalWrite(reset,LOW);
delay(50);
digitalWrite(reset,HIGH);
delay(50);
myservo.attach(10); // attaches the servo on pin 10 to the servo object
myservo.write(90); //center servo
delay(500); //delay 1000ms
}
void forward()
{
//left motor
unsigned char buff1[6];
buff1[0]=0x80; //start byte
buff1[1]=0x00; //device type
buff1[2]=0x00; //motor number and directiobyte; motor one =00,01
buff1[3]=0x7F; //motor speed 0 to 128 in hex (ex 100 is 64 hex)
for (int i=0; i<4; i++) {Serial.print(buff1[i],BYTE);}
//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x02; //motor and direction byte; motor two=02.03
buff2[3]=0x7E;//7E is 126 in hex; 7D is 125 in hex set to smaller value to compensate for uneven wheel speed???
for(int i=0; i<4; i++) {Serial.print(buff2[i],BYTE);}
}
void rightWall(){
//left motor
unsigned char buff3[6];
buff3[0]=0x80;
buff3[1]=0x00;
buff3[2]=0x00;
buff3[3]=0x40;
for(int i=0; i<4; i++) {Serial.print(buff3[i], BYTE);}
//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x02; //motor and direction byte; motor two=02.03
buff2[3]=0x7D;
for(int i=0; i<4; i++) {Serial.print(buff2[i],BYTE);}
}
void leftWall(){
//left motor
unsigned char buff3[6];
buff3[0]=0x80;
buff3[1]=0x00;
buff3[2]=0x00;
buff3[3]=0x7F;
for(int i=0; i<4; i++) {Serial.print(buff3[i], BYTE);}
//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x02; //motor and direction byte; motor two=02.03
buff2[3]=0x7D;
for(int i=0; i<4; i++) {Serial.print(buff2[i],BYTE);}
}
void reverse(){
//left motor
unsigned char buff3[6];
buff3[0]=0x80;
buff3[1]=0x00;
buff3[2]=0x01;
buff3[3]=0x45;
for(int i=0; i<4; i++) {Serial.print(buff3[i], BYTE);}
//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x03; //motor and direction byte; motor two=02.03
buff2[3]=0x45;
for(int i=0; i<4; i++) {Serial.print(buff2[i],BYTE);}
}
void leftTurn(){
//left motor
unsigned char buff3[6];
buff3[0]=0x80;
buff3[1]=0x00;
buff3[2]=0x00;
buff3[3]=0x45;
for(int i=0; i<4; i++) {Serial.print(buff3[i], BYTE);}
//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x02; //motor and direction byte; motor two=02.03
buff2[3]=0x7D;
for(int i=0; i<4; i++) {Serial.print(buff2[i],BYTE);}
}
void rightTurn(){
//left motor
unsigned char buff3[6];
buff3[0]=0x80;
buff3[1]=0x00;
buff3[2]=0x00;
buff3[3]=0x7F;
for(int i=0; i<4; i++) {Serial.print(buff3[i], BYTE);}
//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x02; //motor and direction byte; motor two=02.03
buff2[3]=0x45;
for(int i=0; i<4; i++) {Serial.print(buff2[i],BYTE);}
}
void loop(){
{
long duration, inches, inches2, inches3; // establish variables for duration of ping, inches = 90; inches2 = 20; inches3 = 140
myservo.write(90); //move servo to pos 0
delay(5);
pinMode(ping, OUTPUT);
digitalWrite(ping, LOW);
delayMicroseconds(2);
digitalWrite(ping, HIGH);
delayMicroseconds(5);
digitalWrite(ping, LOW);
pinMode(ping, INPUT);
duration = pulseIn(ping, HIGH);
inches = microsecondsToInches(duration);
myservo.write(20); //move servo to pos 20
delay(5);
pinMode(ping, OUTPUT);
digitalWrite(ping, LOW);
delayMicroseconds(2);
digitalWrite(ping, HIGH);
delayMicroseconds(5);
digitalWrite(ping, LOW);
pinMode(ping, INPUT);
duration = pulseIn(ping, HIGH);
inches2 = microsecondsToInches(duration);
myservo.write(90); //move servo to pos 0
delay(5);
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches3 = microsecondsToInches(duration);
}
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
void wall()
}
if(inches > 50 ){
forward();
}
if (inhes2 < 12){
rightWall();
}
if (inches3 < 12){
leftWall();
}
if (inches < 50 && inches3 < 12){
lerftTurn();
}
if (inches < 50 && inches2 < 12){
rightTurn();
}
}
and heres the report i get when i compile it
sketch_may26c:175 error: expected initializer before '}' token
sketch_may26c:175 error: expected declaration before '}' token