SYMA X5C dengan NRF24L01
Litar yang kawe bina. |
Sambungan :
Kod yang telah kawe ubah untuk ujian.
[code]
/* symax_rx.ino -- An arduino sketch to test the protocol symax
*
*/
#include <SPI.h>
#include <symax_protocol.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
nrf24l01p wireless;
symaxProtocol protocol;
unsigned long time = 0;
int outputValue = 0;
int outputValue2 =0;
void setup() {
Serial.begin(57600);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(3,OUTPUT);
myservo.attach(8); // attaches the servo on pin 8 to the servo object
// SS pin must be set as output to set SPI to master !
pinMode(SS, OUTPUT);
// Set CE pin to 10 and CS pin to 9
wireless.setPins(10,9);
// Set power (PWRLOW,PWRMEDIUM,PWRHIGH,PWRMAX)
wireless.setPwr(PWRLOW);
protocol.init(&wireless);
time = micros();
Serial.println("Start");
}
rx_values_t rxValues;
unsigned long newTime;
void loop()
{
time = micros();
uint8_t value = protocol.run(&rxValues);
newTime = micros();
switch( value )
{
case NOT_BOUND:
Serial.println("Not bound");
digitalWrite(5,LOW);
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
break;
case BIND_IN_PROGRESS:
Serial.println("Bind in progress");
digitalWrite(6,HIGH);
delay(500);
digitalWrite(6,LOW);
delay(500);
digitalWrite(6,HIGH);
delay(500);
digitalWrite(6,LOW);
delay(500);
digitalWrite(6,HIGH);
delay(500);
digitalWrite(6,LOW);
delay(500);
break;
case BOUND_NEW_VALUES:
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
Serial.print(newTime - time);
Serial.print(" :\t");Serial.print(rxValues.throttle);
Serial.print("\t"); Serial.print(rxValues.yaw);
Serial.print("\t"); Serial.print(rxValues.pitch);
Serial.print("\t"); Serial.print(rxValues.roll);
Serial.print("\t"); Serial.print(rxValues.trim_yaw);
Serial.print("\t"); Serial.print(rxValues.trim_pitch);
Serial.print("\t"); Serial.print(rxValues.trim_roll);
Serial.print("\t"); Serial.print(rxValues.video);
Serial.print("\t"); Serial.print(rxValues.picture);
Serial.print("\t"); Serial.print(rxValues.highspeed);
Serial.print("\t"); Serial.println(rxValues.flip);
//time = newTime;
myservo.write(map(rxValues.roll, -127, 127, 0, 180)); // tell servo to go to position
// outputValue = map(rxValues.yaw,0,127,0,255);
//outputValue2 = map(rxValues.yaw,0,-127,0,255);
analogWrite(3,rxValues.throttle);
// analogWrite(5,rxValues.pitch);
//analogWrite(6,outputValue);
//analogWrite(6,outputValue2);
analogWrite(6,rxValues.yaw);
break;
case BOUND_NO_VALUES:
//Serial.print(newTime - time); Serial.println(" : ----");
break;
default:
break;
}
}
[/code]
Video ujian :
https://youtu.be/nL16P1-xNtc
Terima kasih kepada penulis kod yang asal,anda boleh rujuk akaun github beliau di pautan dibawah.
Kod asal:
https://github.com/Suxsem/symaxrx