roboforum.ruТехнический форум по робототехнике. |
|
|
if(button > 1500 || button == 0)
digitalWrite(8, HIGH);
#include "rc_ch4.h"
Receiver_4ch receiver;
long button = 1500;
long gas = 1500;
long rudder = 1500;
long left = 0;
long right = 0;
void setup() {
//Serial.begin(115200);
//Serial.println("RC tank run");
pinMode(8, OUTPUT);
pinMode(3, OUTPUT);
pinMode(6, OUTPUT);
pinMode(11, OUTPUT);
receiver.initialize();
}
void loop() {
receiver.read();
button = receiver.getRaw(CH_1);
gas = receiver.getRaw(CH_2);
rudder = receiver.getRaw(CH_3);
//Serial.print(button); Serial.print("\t");
//Serial.print(gas); Serial.print("\t");
//Serial.println(rudder);
if(button > 1500 || button == 0)
{left = 0;
right = 0;
}
else
{
rudder = rudder - 1500;
left = gas + rudder;
right = gas - rudder;
left = constrain(left, 1100, 1900);
right = constrain(right, 1100, 1900);
if(left >= 1550)
{ digitalWrite(8, HIGH);
left = left - 1550;
left = map(left, 0, 350, 0, 255);
}
else
{ digitalWrite(8, LOW);
if(left <= 1450)
{
left = 1450 - left ;
left = map(left, 0, 350, 0, 255);
}
else
{left = 0;
}
}
if(right >= 1550)
{ digitalWrite(3, HIGH);
right = right - 1550;
right = map(right, 0, 350, 0, 255);
}
else
{ digitalWrite(3, LOW);
if(right <= 1450)
{
right = 1450 - right ;
right = map(right, 0, 350, 0, 255);
}
else
{right = 0;
}
}
//Serial.print(left); Serial.print("\t");
//Serial.println(right);
}
analogWrite(6, left);
analogWrite(11, right);
//delay (10);
}
Вернуться в Новичкам или основы основ роботостроения.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 23