Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
//Transmitte#include #include #include const uint64_t my_radio_pipe = 0xE8E8F0F0E1LL;RF24 radio(9, 10);struct Data_to_be_sent { byte ch1; byte ch2;};Data_to_be_sent sent_data;void setup() { radio.begin(); radio.setAutoAck(false); radio.setDataRate(RF24_250KBPS); radio.openWritingPipe(my_radio_pipe); sent_data.ch1 = 127; sent_data.ch2 = 127;}void loop() { sent_data.ch1 = map(analogRead(A0), 0, 1024, 0, 255); sent_data.ch2 = map(analogRead(A1), 0, 1024, 0, 255); radio.write(&sent_data, sizeof(Data_to_be_sent));}//Receiver#include #include #include #include const uint64_t pipeIn = 0xE8E8F0F0E1LL;RF24 radio(9, 10);Servo myservo;#define in1 3#define in2 4#define enA 5int motorspeed = 0;struct Received_data { byte ch1; byte ch2;};Received_data received_data;int ch1_value = 0;int ch2_value = 0;void reset_the_Data() { received_data.ch1 = 128; received_data.ch2 = 0;}void setup() { pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(enA, OUTPUT); analogWrite(enA, motorspeed); myservo.attach(2); reset_the_Data(); Serial.begin(9600); radio.begin(); radio.setAutoAck(false); radio.setDataRate(RF24_250KBPS); radio.openReadingPipe(1, pipeIn); radio.startListening();}unsigned long lastRecvTime = 0;void receive_the_data() { while (radio.available()) { radio.read(&received_data, sizeof(Received_data)); lastRecvTime = millis(); }}void loop() { receive_the_data(); unsigned long now = millis(); if (now - lastRecvTime > 1000) { reset_the_Data(); } ch1_value = map(received_data.ch1, 0, 255, 0, 255); ch2_value = map(received_data.ch2, 0, 255, 0, 180); myservo.write(ch2_value); if (ch1_value < 126) { digitalWrite(in1, HIGH); digitalWrite(in2, LOW); motorspeed = map(ch1_value, 127, 0, 0, 255); analogWrite(enA, motorspeed); } else if (ch1_value > 130) { digitalWrite(in1, LOW); digitalWrite(in2, HIGH); motorspeed = map(ch1_value, 127, 255, 0, 255); analogWrite(enA, motorspeed); } else { motorspeed = 0; analogWrite(enA, motorspeed); } Serial.print(ch1_value); Serial.println(ch2_value); delay(10);}
👍❤
//Transmitte
#include
#include
#include
const uint64_t my_radio_pipe = 0xE8E8F0F0E1LL;
RF24 radio(9, 10);
struct Data_to_be_sent {
byte ch1;
byte ch2;
};
Data_to_be_sent sent_data;
void setup() {
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(my_radio_pipe);
sent_data.ch1 = 127;
sent_data.ch2 = 127;
}
void loop() {
sent_data.ch1 = map(analogRead(A0), 0, 1024, 0, 255);
sent_data.ch2 = map(analogRead(A1), 0, 1024, 0, 255);
radio.write(&sent_data, sizeof(Data_to_be_sent));
}
//Receiver
#include
#include
#include
#include
const uint64_t pipeIn = 0xE8E8F0F0E1LL;
RF24 radio(9, 10);
Servo myservo;
#define in1 3
#define in2 4
#define enA 5
int motorspeed = 0;
struct Received_data {
byte ch1;
byte ch2;
};
Received_data received_data;
int ch1_value = 0;
int ch2_value = 0;
void reset_the_Data() {
received_data.ch1 = 128;
received_data.ch2 = 0;
}
void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enA, OUTPUT);
analogWrite(enA, motorspeed);
myservo.attach(2);
reset_the_Data();
Serial.begin(9600);
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1, pipeIn);
radio.startListening();
}
unsigned long lastRecvTime = 0;
void receive_the_data() {
while (radio.available()) {
radio.read(&received_data, sizeof(Received_data));
lastRecvTime = millis();
}
}
void loop() {
receive_the_data();
unsigned long now = millis();
if (now - lastRecvTime > 1000) {
reset_the_Data();
}
ch1_value = map(received_data.ch1, 0, 255, 0, 255);
ch2_value = map(received_data.ch2, 0, 255, 0, 180);
myservo.write(ch2_value);
if (ch1_value < 126) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
motorspeed = map(ch1_value, 127, 0, 0, 255);
analogWrite(enA, motorspeed);
} else if (ch1_value > 130) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
motorspeed = map(ch1_value, 127, 255, 0, 255);
analogWrite(enA, motorspeed);
} else {
motorspeed = 0;
analogWrite(enA, motorspeed);
}
Serial.print(ch1_value);
Serial.println(ch2_value);
delay(10);
}
👍❤