Line 17... |
Line 17... |
17 |
|
17 |
|
18 |
|
18 |
|
19 |
// receiving words with RF01 |
19 |
// receiving words with RF01 |
20 |
|
20 |
|
21 |
#include <RF01.h> |
21 |
#include <RF01.h> |
- |
|
22 |
#include <Servo.h> |
- |
|
23 |
|
- |
|
24 |
Servo servo_motor; |
- |
|
25 |
Servo servo_rudder; |
22 |
|
26 |
|
23 |
void setup() |
27 |
void setup() |
24 |
{ |
28 |
{ |
25 |
Serial.begin(9600); |
29 |
Serial.begin(9600); |
26 |
Serial.println("\nRFM01 init"); |
30 |
Serial.println("\nRFM01 init"); |
27 |
delay(250); |
31 |
delay(250); |
28 |
|
32 |
|
- |
|
33 |
servo_motor.attach(3); |
- |
|
34 |
servo_rudder.attach(4); |
- |
|
35 |
|
29 |
rf01_prepAll(); |
36 |
rf01_prepAll(); |
30 |
|
37 |
|
31 |
Serial.println("done"); |
38 |
Serial.println("done"); |
32 |
} |
39 |
} |
33 |
|
40 |
|
34 |
void loop() |
41 |
void loop() |
35 |
{ |
42 |
{ |
36 |
int n; |
43 |
int n; |
- |
|
44 |
unsigned int Motor, Rudder, Check, Check2; |
- |
|
45 |
|
37 |
char* buf = (char*) _rx_buffer; |
46 |
char* buf = (char*) _rx_buffer; |
38 |
|
47 |
|
39 |
rf01_rxdata(_rx_buffer, 10); |
48 |
rf01_rxdata(_rx_buffer, 3); |
- |
|
49 |
Serial.print(buf); |
- |
|
50 |
Serial.print(' '); |
- |
|
51 |
|
- |
|
52 |
Motor=_rx_buffer[0]; |
- |
|
53 |
Motor-=(Motor>'9')?('a'-10):'0'; |
- |
|
54 |
Serial.print(Motor, DEC); Serial.print(' '); |
- |
|
55 |
Rudder=_rx_buffer[1]; |
- |
|
56 |
Rudder-=(Rudder>'9')?('a'-10):'0'; |
- |
|
57 |
Serial.print(Rudder, DEC); Serial.print(' '); |
40 |
buf[11]=0; |
58 |
Check=_rx_buffer[2]; |
- |
|
59 |
Check-=(Check>'9')?('a'-10):'0'; |
- |
|
60 |
Serial.print(Check, DEC); Serial.print(' '); |
- |
|
61 |
|
- |
|
62 |
Check2=Motor+Rudder; |
- |
|
63 |
if (Check2>32) Check2-=32; |
- |
|
64 |
if (Check!=Check2) |
- |
|
65 |
{Serial.print(' Error');} |
- |
|
66 |
else |
- |
|
67 |
{ |
- |
|
68 |
servo_motor.write(Motor); |
- |
|
69 |
servo_rudder.write(Rudder); |
- |
|
70 |
} |
41 |
|
71 |
|
42 |
Serial.println(buf); |
- |
|
43 |
for(n=0;n<32;n++) {Serial.print(buf[n], HEX); Serial.print(' ');} |
- |
|
44 |
Serial.println(); |
72 |
Serial.println(); |
45 |
} |
73 |
} |