Ok what do you think about this ??
double ch1=PB3; // flysky ch 1
int IN1=PB5; //
int IN2=PB6; //
double ch2=PB4; // flysky ch 2
int IN3=PB7; //
int IN4=PB8; //
const int ENA = PA3;
const int ENB = PA4;
void setup()
{
Serial.begin(9600);
pinMode(PB3,INPUT);
pinMode(PB5,OUTPUT); pinMode(PB6,OUTPUT);
pinMode(PB4,INPUT);
pinMode(PB7,OUTPUT); pinMode(PB8,OUTPUT);
pinMode (ENA, OUTPUT);
pinMode (ENB, OUTPUT);
}
void loop()
{
int pwm1 = 0;
int pwm2 = 0;
ch1 = pulseIn(PB3,HIGH, 25000);
ch2 = pulseIn(PB4,HIGH, 25000);
//control speed
// analogWrite(ENA, 255);
// analogWrite(ENB, 255);
//ch1 = pulseIn(PB3,HIGH);
//ch2 = pulseIn(PB4,HIGH);
if((ch1==0)&&(ch2==0))
{
digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);
analogWrite(ENA, 0);analogWrite(ENB, 0);
}
//Przód
else if((ch1>1520)&&(ch2>1520))
{
pwm1 = map(ch1, 1520, 2000, 0, 255);
pwm2 = map(ch2, 1520, 2000, 0, 255);
digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);
analogWrite(ENA, pwm1);analogWrite(ENB, pwm2);
}
else if((ch1>1520)&&(ch2<1500))
//PRAWO
{
pwm1 = map(ch1, 1495, 2000, 0, 255);
pwm2 = map(ch2, 1502, 2000, 0, 255);
digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);
analogWrite(ENA, pwm1);analogWrite(ENB, 0);
}
//LEWO
else if((ch1<1480)&&(ch2>1500))
{
pwm1 = map(ch1, 1493, 2000, 0, 255);
pwm2 = map(ch2, 1504, 2000, 0, 255);
digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);
analogWrite(ENA, 0);analogWrite(ENB, pwm2);
}
//Tył
else if((ch1<1490)&&(ch2<1490))
{
pwm1 = map(ch1, 1490, 2000, 0, 255);
pwm2 = map(ch2, 1490, 2000, 0, 255);
digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);
analogWrite(ENA, pwm1);analogWrite(ENB, pwm2);
}
else
{
digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);
analogWrite(ENA, 0);analogWrite(ENB, 0);
}
}
But not work good only one channel works good ;(
Ok I Read value from channel1 and ch2 but not work:
//FRONT
Ch1: 1724 Ch2: 1743
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1741 Ch2: 1749
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1741 Ch2: 1751
//BACK
Ch1: 1244 Ch2: 1253
Ch1: 1244 Ch2: 1253
Ch1: 1244 Ch2: 1252
Ch1: 1245 Ch2: 1254
Ch1: 1244 Ch2: 1253
Ch1: 1245 Ch2: 1253
Ch1: 1244 Ch2: 1253
Ch1: 1244 Ch2: 1253
Ch1: 1241 Ch2: 1253
//LEFT
Ch1: 1009 Ch2: 1503
Ch1: 1009 Ch2: 1503
Ch1: 1009 Ch2: 1503
Ch1: 1006 Ch2: 1501
Ch1: 1009 Ch2: 1503
Ch1: 1008 Ch2: 1503
Ch1: 1010 Ch2: 1502
Ch1: 1008 Ch2: 1503
Ch1: 1008 Ch2: 1503
//RIGHT
Ch1: 1994 Ch2: 1505
Ch1: 1994 Ch2: 1504
Ch1: 1998 Ch2: 1507
Ch1: 1996 Ch2: 1508
Ch1: 1997 Ch2: 1507
Ch1: 1997 Ch2: 1507
Ch1: 1998 Ch2: 1507
Ch1: 1996 Ch2: 1507
Ch1: 1997 Ch2: 1507
Ch1: 1998 Ch2: 1507
Ch1: 1996 Ch2: 1505
Ch1: 1997 Ch2: 1507
Ch1: 1996 Ch2: 1506
Ch1: 1995 Ch2: 1505
Ch1: 1994 Ch2: 1504
Ch1: 1995 Ch2: 1505
//ZERO
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1504
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1504
Ch1: 1494 Ch2: 1503