KIWI project

Hi, please could someone gives me some tip how to do it ?
I send 6bytes to arduino from pc across serial and i would like to know, how sort this data in arduino ?
Cause when i send byte where is "INT 0" so arduino does not accept this as a byte, so it sets first non- zero byte like first byte for first aplication - as set pwm for first motor...
Please has someone some tip how to sort bytes, or how to do it great ?

Thanks Jakub.K.

Do a Tools > Auto Format on your sketch then post your sketch here using code tags(</> button on the toolbar).

It is not solving my problem... pls read my story . thx Jack.

(deleted)

Ok i am realy sory it is my fail with non - sharing code. Here it is :

#include <Servo.h>
int dirPin1M1 = 3; // nastavení směru 1 motoru 1
int dirPin2M1 = 4; // nastavení směru 2 motoru 1
int pwmPin1 = 5; // výstup PWM1
int dirPin1M2 = 7; // nastavení směru 1 motoru 2
int dirPin2M2 = 8; // nastavení směru 2 motoru 2
int pwmPin2 = 6; // výstup PWM2
byte x1, x2, x3, x4;
Servo m1Servo;
Servo m2Servo;
int duty1, duty2, duty3, duty4;

void setup()
{
m1Servo.attach(9);//definice portu připojení serva
m2Servo.attach(10);//definice portu připojení serva
Serial.begin(9600);

pinMode(dirPin1M1, OUTPUT);
pinMode(dirPin2M1, OUTPUT);
pinMode( pwmPin1, OUTPUT);
pinMode(dirPin1M2, OUTPUT);
pinMode( dirPin2M2, OUTPUT);
pinMode( pwmPin2, OUTPUT);

digitalWrite(pwmPin1, LOW);
digitalWrite(pwmPin2, LOW);
digitalWrite(dirPin1M1, LOW);
digitalWrite(dirPin2M1, LOW);
digitalWrite(dirPin1M2, LOW);
digitalWrite(dirPin2M2, LOW);

}

void loop() {

if (Serial.available() == 4)
{
x1 = (Serial.read());

int duty1 = (x1) & 0b01111111;
if (x1 & 0b10000000)
{
digitalWrite(dirPin1M1, 1);
digitalWrite(dirPin2M1, 0);
}
else
{
digitalWrite(dirPin2M1, 1);
digitalWrite(dirPin1M1, 0);
}

x2 = ( Serial.read());

int duty2 = (x2) & 0b01111111;
if (x2 & 0b10000000)
{
digitalWrite(dirPin1M2, 1);
digitalWrite(dirPin2M2, 0);
}
else
{
digitalWrite(dirPin2M2, 1);
digitalWrite(dirPin1M2, 0);
}

x3 = (Serial.read());

int duty3 = x3;
m1Servo.write(0);//nastav servo uhel 0
m1Servo.write(duty3 * 2); //nastav servo uhel x

x4 = (Serial.read());

int duty4 = x4;
m2Servo.write(0);//nastav servo uhel 0
m2Servo.write(duty4 * 2); //nastav servo uhel x

analogWrite(pwmPin1, duty1 * 2);
analogWrite(pwmPin2, duty2 * 2);

}
}

Just curious, why is this a "KIWI" project?

i am sending 4 bytes across serial line to arduino, which contain :
byte1(0 - 127 for pwm1) for motor1,
byte2(0 - 127 for pwm2) for motor2,
byte3(0 - 180 like a degree) for servo1,
byte4(0 - 180 like a degree) for servo2.

And you asked me what it mean:

int duty1 = (x1) & 0b01111111;
if (x1 & 0b10000000).

it takes first bit from byte and checked it, if it is 1 or 0 and it says direction of motor.
And in duty it filtres only 7 bits for pwm...

Thanks Jack.

i am sending 4 bytes across serial line to arduino,

What is sending the serial data to the Arduino, and what is the sending format.