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 {
2141 kakl 37 unsigned char _tx_buffer[]="mrc";
2139 kakl 38 unsigned int Motor;
39 unsigned int Rudder;
2141 kakl 40 unsigned char Check;
2139 kakl 41 signed int ble;
42  
43 Motor = analogRead(A0);
44 Rudder = analogRead(A1);
45  
2151 kakl 46 //!!!
47 Serial.print(Motor, DEC);
48 Serial.print(" * ");
49 Serial.println(Rudder, DEC);
50  
2139 kakl 51 Motor = MotorOffset - Motor;
2151 kakl 52 Rudder=1023-Rudder;
2139 kakl 53 Rudder = 512 - ((RudderOffset - Rudder)<<2);
2141 kakl 54 Motor>>=2;
55 Rudder>>=2;
2151 kakl 56 if (Motor>200) Motor=0; // Odstranit pro programovani regulatoru
2141 kakl 57 if (Rudder>250) Rudder=0;
2151 kakl 58 //if (Rudder<71) Rudder=71;
2139 kakl 59  
60 Check=Motor+Rudder;
2141 kakl 61  
62 _tx_buffer[0]=(unsigned char)Motor;
63 _tx_buffer[1]=(unsigned char)Rudder;
2139 kakl 64 _tx_buffer[2]=Check;
65  
66 rf02_txdata( _tx_buffer, sizeof(_tx_buffer));
67 }
68  
69