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; |
2140 |
kakl |
44 |
unsigned int Motor, Rudder, Check, Check2; |
|
|
45 |
|
2139 |
kakl |
46 |
char* buf = (char*) _rx_buffer; |
|
|
47 |
|
2140 |
kakl |
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(' '); |
|
|
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 |
} |
2139 |
kakl |
71 |
|
|
|
72 |
Serial.println(); |
|
|
73 |
} |