Pages: [1]   Go Down
Author Topic: How to create a string in c++  (Read 489 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I do not know VB but:

Quote
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:

Code:
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 smiley
« Last Edit: March 11, 2009, 06:42:26 pm by AlphaBeta » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if you just want a one character values as in the VB code you can just do:
Code:
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:
Quote
It would be simpler to help you if you explained a bit more detailed what it is you want to accomplish though
« Last Edit: March 12, 2009, 01:02:38 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i figured it out, im not done yet, see if it powers on the motors on your arduino boards,  
Code:
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
    }
 
}
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You code sets pin 13 and 10 HIGH.


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

Pages: [1]   Go Up
Jump to: