2139 |
kakl |
1 |
/* |
|
|
2 |
RF02 TX duckweed collector |
|
|
3 |
|
|
|
4 |
in arduino version 022 |
|
|
5 |
|
|
|
6 |
tested with MLAB modules with ATmega 328 at 16MHz |
|
|
7 |
see RF02 library for a Band and Frequency |
|
|
8 |
*/ |
|
|
9 |
|
|
|
10 |
//connections RF01: (RX) |
|
|
11 |
// RF01 SDI, arduino 13, ATmega PB5, cannot be changed |
|
|
12 |
// RF01 SCK, arduino 12, ATmega PB4, cannot be changed |
|
|
13 |
// RF01 nSEL, arduino 11, ATmega PB3, cannot be changed |
|
|
14 |
// RF01 SDO, arduino 10, ATmega PB2, cannot be changed |
|
|
15 |
// RF01 niRQ, arduino 02, ATmega PD2, cannot be changed |
|
|
16 |
// RF01 nFFS: 1-10k Pullup too Vcc |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
// receiving words with RF01 |
|
|
20 |
|
|
|
21 |
#include <RF01.h> |
2140 |
kakl |
22 |
#include <Servo.h> |
2139 |
kakl |
23 |
|
2140 |
kakl |
24 |
Servo servo_motor; |
|
|
25 |
Servo servo_rudder; |
|
|
26 |
|
2139 |
kakl |
27 |
void setup() |
|
|
28 |
{ |
|
|
29 |
Serial.begin(9600); |
|
|
30 |
Serial.println("\nRFM01 init"); |
|
|
31 |
delay(250); |
|
|
32 |
|
2140 |
kakl |
33 |
servo_motor.attach(3); |
|
|
34 |
servo_rudder.attach(4); |
|
|
35 |
|
2139 |
kakl |
36 |
rf01_prepAll(); |
|
|
37 |
|
|
|
38 |
Serial.println("done"); |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
void loop() |
|
|
42 |
{ |
|
|
43 |
int n; |
2141 |
kakl |
44 |
unsigned char Motor, Rudder, Check, Check2; |
2140 |
kakl |
45 |
|
2139 |
kakl |
46 |
char* buf = (char*) _rx_buffer; |
|
|
47 |
|
2140 |
kakl |
48 |
rf01_rxdata(_rx_buffer, 3); |
2141 |
kakl |
49 |
// Serial.print(buf); |
|
|
50 |
// Serial.print(' '); |
2140 |
kakl |
51 |
|
|
|
52 |
Motor=_rx_buffer[0]; |
2141 |
kakl |
53 |
// Serial.print(Motor, DEC); Serial.print(' '); |
2140 |
kakl |
54 |
Rudder=_rx_buffer[1]; |
2141 |
kakl |
55 |
// Serial.print(Rudder, DEC); Serial.print(' '); |
2140 |
kakl |
56 |
Check=_rx_buffer[2]; |
2141 |
kakl |
57 |
// Serial.print(Check, DEC); Serial.print(' '); |
2140 |
kakl |
58 |
|
|
|
59 |
Check2=Motor+Rudder; |
|
|
60 |
if (Check!=Check2) |
2141 |
kakl |
61 |
{ |
|
|
62 |
// {Serial.print(Check2,DEC);} |
|
|
63 |
} |
2140 |
kakl |
64 |
else |
|
|
65 |
{ |
2141 |
kakl |
66 |
servo_motor.write(Motor+45); |
|
|
67 |
servo_rudder.write(Rudder/2+45); |
2140 |
kakl |
68 |
} |
2139 |
kakl |
69 |
|
2141 |
kakl |
70 |
delay(15); |
|
|
71 |
// Serial.println(); |
2139 |
kakl |
72 |
} |