我正在使用2个arduino uno和433 two射频模块,我试图通过改变电位器的值来分别移动两个伺服电机。
但我的代码把伺服器放在一起。我想当我改变第一个电位器的值时,第一个伺服移动,当我改变第二个时,第二个伺服移动。
这是我的发送器代码:
//Transmitter Code
#include <RCSwitch.h>
RCSwitch myswitch = RCSwitch();
int pot = A0;
int pot1 = A1;
void setup() {
Serial.begin(9600);
myswitch.enableTransmit(10);
}
void loop() {
int pott = analogRead(pot);
int pott1 = analogRead(pot1);
int servo= map(pott,0,1024,1,180);
int servo1= map(pott1,0,1024,1,180);
myswitch.send(servo, 10);
delay(200);
myswitch.send(servo1, 10);
delay(200);
}....
这是我的接收器代码
//Receiver Code:
#include <RCSwitch.h>
#include <Servo.h>
int pos = 0;
Servo myservo;
Servo myservo1;
RCSwitch myswitch = RCSwitch();
void setup() {
myservo.attach(10);
myservo1.attach(11);
Serial.begin(9600);
myswitch.enableReceive(0);
}
void loop() {
if (myswitch.available()){
int angle = myswitch.getReceivedValue();
int angle1 = myswitch.getReceivedValue();
myservo.write(angle);
delay(200);
myservo1.write(angle1);
delay(200);
}
}发布于 2018-12-19 12:54:22
发送两个值,因为它们可以区分,就像在发送器中一样,
myswitch.send(servo, 10);
delay(200);
myswitch.send(servo1 + 1000, 10);然后换个接收器
if (myswitch.available()){
int value = myswitch.getReceivedValue();
if(value > 1000)
myservo1.write(value - 1000);
else
myservo.write(value);
delay(200);
}https://stackoverflow.com/questions/53832198
复制相似问题