//xsetaseta@gmail.com #include <SPI.h>
#include "RF24.h"
#include <Servo.h>
#define debug 0
Servo myservo1;
Servo myservo2;
Servo myservo3;
int posicion;
bool done;
const int analogOutPin = 5;
unsigned char cadena[10];
int z;
//RF24 (cepin, cspin)
RF24 radio(8,7);
// Topology
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup()
{
Serial.begin(9600);
myservo1.attach(2);
myservo2.attach(3);
myservo3.attach(4);
radio.begin();
radio.setRetries(15,15);
radio.startListening();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
Serial.println("Esperando datos");
}
void loop()
{
delay(10);
if ( radio.available() )
{
done = false;
while (!done)
{
done = radio.read( cadena, 6);
#if debug
Serial.print(cadena[0]);Serial.print(" ");
Serial.print(cadena[1],DEC);Serial.print(" ");
Serial.print(cadena[2],DEC);Serial.print(" ");
Serial.print(cadena[3],DEC);Serial.println(" ");
#endif
z=cadena[0];
switch(z)
{
case 65:
posicion = map(cadena[1], 0, 254, 0, 179); myservo1.write(posicion);
posicion = map(cadena[2], 0, 254, 0, 179); myservo2.write(posicion);
posicion = map(cadena[3], 0, 254, 0, 179); myservo3.write(posicion);
analogWrite(analogOutPin, cadena[3]);
break;
}
radio.stopListening();
delay(10);
radio.startListening();
}
}
}
|