Rev Author Line No. Line
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 RF02: (TX)
11 // SDI, -> RF02 Atmega PB0 Arduino 8 cannot be changed
12 // SCK, -> RF02 Atmega PB1 Arduino 9 cannot be changed
13 // nSEL, -> RF02 Atmega PB2 Arduino 10 cannot be changed
14 // nIRQ, <- RF02 Atmega PB4 Arduino 12 cannot be changed
15 // FSK: Pullupto VCC
16  
17 #include <RF02.h>
18  
19 unsigned int MotorOffset;
20 unsigned int RudderOffset;
21  
22 void setup()
23 {
24 Serial.begin(9600);
25 Serial.println("\nSTM02 init" );
26  
27 MotorOffset = analogRead(A0);
28 RudderOffset = analogRead(A1);
29  
30 rf02_prepAll();
31  
32 Serial.println("done" );
33 }
34  
35 void loop()
36 {
37 unsigned char _tx_buffer[]="aab\0";
38 unsigned int Motor;
39 unsigned int Rudder;
40 unsigned int Check;
41 signed int ble;
42  
43 Motor = analogRead(A0);
44 Rudder = analogRead(A1);
45  
46 Motor = MotorOffset - Motor;
47 Rudder = 512 - ((RudderOffset - Rudder)<<2);
48 Motor>>=4;
49 Rudder>>=5;
50  
51 if (Motor>32) Motor=0;
52 if (Rudder>32) Rudder=0;
53 Check=Motor+Rudder;
54 if (Check>32) Check-=32;
55  
56 Motor+=(Motor>9)?('a'-10):'0';
57 Rudder+=(Rudder>9)?('a'-10):'0';
58 Check+=(Check>9)?('a'-10):'0';
59  
60 _tx_buffer[0]=Motor;
61 _tx_buffer[1]=Rudder;
62 _tx_buffer[2]=Check;
63  
64 rf02_txdata( _tx_buffer, sizeof(_tx_buffer));
65 }
66  
67