/*
RF02 TX duckweed collector

in arduino version 022

tested with MLAB modules with ATmega 328 at 16MHz
see RF02 library for a Band and Frequency
*/

//connections RF01: (RX)
// RF01  SDI,  arduino  13, ATmega PB5, cannot be changed
// RF01  SCK,  arduino  12, ATmega PB4, cannot be changed
// RF01  nSEL, arduino  11, ATmega PB3, cannot be changed
// RF01  SDO,  arduino  10, ATmega PB2, cannot be changed
// RF01  niRQ, arduino  02, ATmega PD2, cannot be changed
// RF01  nFFS: 1-10k Pullup too Vcc


// receiving words with RF01

#include <RF01.h>
#include <Servo.h> 

Servo servo_motor;
Servo servo_rudder;

void setup() 
{
  Serial.begin(9600);
  Serial.println("\nRFM01 init");
  delay(250);

  servo_motor.attach(3);  
  servo_rudder.attach(4); 

  rf01_prepAll();

  Serial.println("done");
}

void loop() 
{
  int n;
  unsigned int Motor, Rudder, Check, Check2;
  
  char* buf = (char*) _rx_buffer;

  rf01_rxdata(_rx_buffer, 3); 
  Serial.print(buf);
  Serial.print(' ');
  
  Motor=_rx_buffer[0];
  Motor-=(Motor>'9')?('a'-10):'0';
  Serial.print(Motor, DEC); Serial.print(' ');
  Rudder=_rx_buffer[1];
  Rudder-=(Rudder>'9')?('a'-10):'0';
  Serial.print(Rudder, DEC); Serial.print(' ');
  Check=_rx_buffer[2];
  Check-=(Check>'9')?('a'-10):'0';
  Serial.print(Check, DEC); Serial.print(' ');
  
  Check2=Motor+Rudder;
  if (Check2>32) Check2-=32;  
  if (Check!=Check2) 
    {Serial.print(' Error');}
  else
  {
    servo_motor.write(Motor);
    servo_rudder.write(Rudder);
  }

  Serial.println();  
}