Hi, I tried another forum but no one...


ok, found code , learned does, unfortunately, still can't figure out how change  code have rely on 1 ping sensor. need help, , i've tried everything. learned python simplify , understand code better. (i my, it's not mine, borrowed majority of it. ) i'd prefer if of guys keep pretty humane comments.here code. not comments. please nice, i'm noob.
quote
//sketch written imm//rroboto convert rc truck robot using 3 ping sensors,
//an arduino uno , //seeed studio motor shield.  built upon ping example code
//tom igoe , motor //shield tutorial sketch seeed studio.


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 steerpinb=10;//enable motor b
int speed_drive =420;//define speed of drive motor
int speed_steer =1524;//define speed of steering motor
const int pingpin_r = 7;//sets pin ping sensor on right side of car
const int pingpin_c = 6;//sets pin ping sensor in center side of car
const int pingpin_l = 5;//sets pin ping sensor on left side of car
long duration_c, inches_c,duration_r, inches_r,duration_l, inches_l;

void setup()
{
 pinmode(pini1,output);
 pinmode(pini2,output);
 pinmode(speedpina,output);
 pinmode(pini3,output);
 pinmode(pini4,output);
 pinmode(steerpinb,output);
}

void loop()
{
 int i;
 int j = 1;
 delay(5000);
 for(i=0; i<1; i*1){
 j++;
 getping_all();


//all clear, no obstacles within 30" in direction
 if(inches_c >= 30 && inches_r >= 30 && inches_l >= 30)
 {
  forward();
 }

//obstacle(s) within 0-6" range
 else if (inches_l < 6 || inches_c < 6 || inches_r < 6)
 {
  stop();
  backward();
  delay(1500);
  stop();
    if(j%3 == 0){ //this if/else statement designed build little "randomness"
    back_right(); //into robot's movements, less become stuck
    back_right(); //in loop, performing same actions on , on only.
    left();
    j=1;
    }
  else{
    back_left();
    back_left();
    right();
    }
 }

//obstacle(s) within 6"-12" range

 //obstacle on left , center , right
 else if (inches_r < 12 && inches_c < 12 && inches_l < 12)
 {
  stop();
  backward();
  delay(1500);
  back_left();
  stop();
  right();
  forward();
 }


character limit :)

next half
 //obstacle on center or left , right
 else if (inches_l >= 12 && inches_r >= 12 && inches_c < 12 ||
           inches_c >= 12 && inches_r < 12 && inches_l < 12)
 {
  stop();
  backward();
  delay(1500);
  back_left();
  stop();
  right();
  forward();
 }
 //obstacle on left , center
 else if (inches_r >= 12 && inches_c < 12 && inches_l < 12)
 {
  stop();
  backward();
  delay(1500);
  back_left();
 }
 //obstacle on right , center
 else if (inches_l >= 12 && inches_c < 12 && inches_r < 12)
 {
  stop();
  backward();
  delay(1500);
  back_right();
 }
 //obstacle on right
 else if (inches_l >= 12 && inches_c >= 12 && inches_r < 12)
 {
  left();
  left();
 
 }
 //obstacle on left
 else if (inches_r >= 12 && inches_c >= 12 && inches_l < 12)
 {
  right();
  right();
 }

//obstacle(s) within 12"-30" range

 //obstacle on left , center
 else if (inches_r >= 30 && inches_c < 30 && inches_l < 30)
 {
  right();
  right();
 }
 //obstacle on right , center
 else if (inches_l >= 30 && inches_c < 30 && inches_r < 30)
 {
  left();
  left();
 }
 //obstacle on right , left
 else if (inches_c >= 30 && inches_l < 30 && inches_r < 30)
 {
  forward();
 }
 //obstacle on right
 else if (inches_l >= 30 && inches_c >= 30 && inches_r < 30)
 {
  left();
 }
 //obstacle on left
 else if (inches_r >= 30 && inches_c >= 30 && inches_l < 30)
 {
  right();
 }
 //obstacle on center
 else if (inches_l >= 30 && inches_r >= 30 && inches_c < 30)
 {
  if(j % 2 == 0){
    left();
    j=1;
  }
  else{
    right();
   }
 } 
 }
}

void forward()
{// turns on drive motor in forward , leaves on
    analogwrite(speedpina,speed_drive);//inputs speed_drive value set speed
    digitalwrite(pini2,low);//turn dc motor move anticlockwise
    digitalwrite(pini1,high);
}
void backward()//
{// turns on drive motor in reverse , leaves on
    analogwrite(speedpina,speed_drive);//inputs speed_drive value set speed
    digitalwrite(pini2,high);//turn dc motor move clockwise
    digitalwrite(pini1,low);
}
void right()//
{
    analogwrite(steerpinb,speed_steer);
    digitalwrite(pini4,high);//turn dc motor b move clockwise
    digitalwrite(pini3,low);
    forward();
    delay(300);
    analogwrite(steerpinb,low);
}
void back_left()//
{
    analogwrite(steerpinb,speed_steer);
    digitalwrite(pini4,high);//turn dc motor b move clockwise
    digitalwrite(pini3,low);
    delay(250);
    backward();
    delay(500);
    stop();
    delay(250);
}
void left()//
{
    analogwrite(steerpinb,speed_steer);
    digitalwrite(pini4,low);//turn dc motor b move anticlockwise
    digitalwrite(pini3,high);
    forward();
    delay(300);
    analogwrite(steerpinb,low);
}
void back_right()//
{
    analogwrite(steerpinb,speed_steer);
    digitalwrite(pini4,low);//turn dc motor b move anticlockwise
    digitalwrite(pini3,high);
    delay(250);
    backward();
    delay(500);
    stop();
    delay(250);
}
void stop()//stop both motors
{
    digitalwrite(speedpina,low);// unenble pin, stop motor.
    digitalwrite(steerpinb,low);// unenble pin, stop motor.
}
void getping_c()//get distance center ping
{
     pinmode(pingpin_c, output);
     digitalwrite(pingpin_c, low);
     delaymicroseconds(2);
     digitalwrite(pingpin_c, high);
     delaymicroseconds(5);
     digitalwrite(pingpin_c, low);
     pinmode(pingpin_c, input);
     duration_c = pulsein(pingpin_c, high);
     inches_c = microsecondstoinches(duration_c);
}
void getping_r()//get distance right ping
{
      pinmode(pingpin_r, output);
      digitalwrite(pingpin_r, low);
      delaymicroseconds(2);
      digitalwrite(pingpin_r, high);
      delaymicroseconds(5);
      digitalwrite(pingpin_r, low);
      pinmode(pingpin_r, input);
      duration_r = pulsein(pingpin_r, high);
      inches_r = microsecondstoinches(duration_r);
}
 void getping_l()//get distance left ping
{
      pinmode(pingpin_l, output);
      digitalwrite(pingpin_l, low);
      delaymicroseconds(2);
      digitalwrite(pingpin_l, high);
      delaymicroseconds(5);
      digitalwrite(pingpin_l, low);
      pinmode(pingpin_l, input);
      duration_l = pulsein(pingpin_l, high);
      inches_l = microsecondstoinches(duration_l);
}
  void getping_all()
{
  getping_c();
  delay(2);
  getping_r();
  delay(2);
  getping_l();
  delay(2);
}
  long microsecondstoinches(long microseconds){
    return microseconds / 74 / 2;}

/* above converts time of return inches explained here: <a href="http://learn.parallax.com/kickstart/28015" rel="nofollow">http://learn.parallax.com/kickstart/28015
</a>*/

[/quote]


Arduino Forum > Using Arduino > Project Guidance > Hi, I tried another forum but no one...


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code