oh okey, i understand now. and you are right about my basics of c, they are bad, but im working on it ^^.
anyway my brother does program c++ and tryed to explain me some parts, he sucseed but that doesnt take all problems away..
i've copied and edit my code now, i have this:
#include <VirtualWire.h>
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
void setup()
{
//Setup VirtualWire to transmit on 4
vw_setup(100);
vw_set_tx_pin(4);
pinMode(13, OUTPUT); //Power LED
digitalWrite(13, HIGH); //Always ON
//setup a serial connection
Serial.begin(57600);
}
void loop()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
if(started && ended)
{
// The end of packet marker arrived. Process the packet
vw_send((uint8_t *)inData, strlen(inData));
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
here is the code of the robot wich im trying to control:
#include <VirtualWire.h>
int m1r = 6; //motor left red wire
int m1b = 5; //motor left black wire
int m2r = 9; //motor right red wire
int m2b = 10; //motor right black wire
void setup()
{
//virtual wire setup
//for recive on pin 4
vw_setup(100);
vw_rx_start();
vw_set_rx_pin(4);
pinMode(13, OUTPUT); //power LED
digitalWrite(13, HIGH); //Always ON
}
void loop()
{
//variables setup
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
char recived;
if(vw_get_message((uint8_t*)recived, &buflen))
{
move(recived);
}
delay(50);
}
//[FUNCTION] ~ move into recived driection (for,bac,lef,rig)
void move(char DIR)
{
//Stop
if(DIR == 'x')
{
analogWrite(m1r, 0);
analogWrite(m1b, 0);
analogWrite(m2r, 0);
analogWrite(m2b, 0);
}
//drive forward
if(DIR == 'f')
{
analogWrite(m1r, 255);
analogWrite(m1b, 0);
analogWrite(m2r, 255);
analogWrite(m2b, 0);
}
//drive backwards
if(DIR == 'b')
{
analogWrite(m1r, 0);
analogWrite(m1b, 255);
analogWrite(m2r, 0);
analogWrite(m2b, 255);
}
//turn left
if(DIR == 'l')
{
analogWrite(m1r, 0);
analogWrite(m1b, 255);
analogWrite(m2r, 255);
analogWrite(m2b, 0);
}
//turn right
if(DIR == 'r')
{
analogWrite(m1r, 255);
analogWrite(m1b, 0);
analogWrite(m2r, 0);
analogWrite(m2b, 255);
}
}
now if i power both and send the letter 'r' trough the serial monitor it doesn't turn right,
is this because of wrong transmition or because something else? (i hope im not going offtoppic)
thanks alot already,
nick