How to create a string in c++

im gonna make a robot with an ardurino usb board soon and i want it to go around my room and avoid obstacles, here's what it would kinda look like in visual basic

private sub me_load(...) Handles Me.load Dim location As String Location.String = "0" If Location.String = "0" Then power on motor1 and 2 then do that for x amount of time then change location.string to "2" once everything has already been executed

sorry of my lack of knowledge but if you can help me then that would be great.

http://arduino.cc/en/Reference/String

I do not know VB but:

private sub me_load(…) Handles Me.load
Dim location As String
Location.String = “0”
If Location.String = “0” Then
power on motor1 and 2
then do that for x amount of time
then change location.string to “2” once everything has already been executed

could look something like:

char location[] = "0";
byte amountOfTimes = 2;

void powerMotor(byte motor); //TODO - implement function

void me_load(){
  for(byte i=0; i<amountOfTimes; i++){
    if(location[0]=='0'){
      powerMotor(1);
      powerMotor(2);
    }
  }
  location[0]='2';
}

It would be simpler to help you if you explained a bit more detailed what it is you want to accomplish though :slight_smile:

if you just want a one character values as in the VB code you can just do:

char location = '0';
byte amountOfTimes = 2;

void powerMotor(byte motor); //TODO - implement function

void me_load(){
  for(byte i=0; i<amountOfTimes; i++){
    if(location == '0'){
      powerMotor(1);
      powerMotor(2);
    }
  }
  location='2';
}

I completly agree with AlphaBeta:

It would be simpler to help you if you explained a bit more detailed what it is you want to accomplish though

i figured it out, im not done yet, see if it powers on the motors on your arduino boards,

int mfl = 13;                // front left motor connected to digital pin 13
int mfr = 10;                // front right motor connected to digital pin 10

void setup()                    // run once, when the sketch starts
{
  pinMode(mfl, OUTPUT);      // sets the digital pin as output
  pinMode(mfr, OUTPUT);
}


  boolean L1 = true;

    void loop()                     // run over and over again
{

    if(L1 == true){
      digitalWrite(mfl, HIGH);   // sets the front left motor on
      digitalWrite(mfr, HIGH); // sets the front right motor on
     delay(10000);                  // waits for 10 seconds
    }

}

You code sets pin 13 and 10 HIGH.

For more information about arduino and motors: http://itp.nyu.edu/physcomp/Labs/DCMotorControl