hey guys im having another problem now with my nrf24l01 it doesetn seem to work im trying to get my 2 joysticks to control my 4 servos wirless and the wirless module doesent seem to work is compiles and uploads fine and everything is on but nothing happens.
transmitter code
/*
---- Transmitter Code ----`Preformatted text`
*/
#include <SPI.h>`Preformatted text`
#include "RF24.h"
int joystick[6];
RF24 radio(7,8);
const uint64_t pipe = 123456;`Preformatted text`
void setup(void)
{
radio.begin();
radio.openWritingPipe(pipe);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
}
void loop(void)
{
joystick[0] = analogRead(0);
joystick[1] = analogRead(1);
joystick[2] = analogRead(2);
joystick[3] = analogRead(3);
joystick[4] = digitalRead(2);
joystick[5] = digitalRead(3);
radio.write(joystick, sizeof(joystick) );
}
and yes, I'm trying to use code tags
and heres the receiver code
/*
---- Receiver Code ----
*/
#include <Servo.h>
#include <SPI.h>
#include "RF24.h"
int positionA = 90;
int positionB = 90;
int positionC = 90;
int positionD = 90;
int positionW = 90;
int positionX = 90;
int positionY = 90;
int positionZ = 90;
Servo myServoA;
Servo myServoB;
Servo myServoC;
Servo myServoD;
Servo myServoW;
Servo myServoX;
Servo myServoY;
Servo myServoZ;
long previousMillis = 0;
long interval = 15;
boolean lastButton2 = LOW;
boolean lastButton3 = LOW;
boolean ledOn2 = false;
boolean ledOn3 = false;
int buttonState2 = 0;
int buttonState3 = 0;
int joystick[6];
RF24 radio(7,8);
const uint64_t pipe = 123456;
int done;
void setup()
{
myServoA.attach(4);
myServoB.attach(5);
myServoC.attach(6);
myServoD.attach(9);
myServoW.attach(14);
myServoX.attach(15);
myServoY.attach(16);
myServoZ.attach(17);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(18, OUTPUT);
pinMode(19, OUTPUT);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();
}
void loop()
{
if(radio.available())
{
bool done = false;
while (!done) {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
if(ledOn2 == LOW)
{
if(joystick[0] < 412 && positionA < 150)
{
positionA++;
myServoA.write(positionA);
}
if(joystick[0] > 612 && positionA > 30)
{
positionA--;
myServoA.write(positionA);
}
if(joystick[1] < 412 && positionB < 150)
{
positionB++;
myServoB.write(positionB);
}
if(joystick[1] > 612 && positionB > 30)
{
positionB--;
myServoB.write(positionB);
}
}
if(ledOn2 == HIGH)
{
if(joystick[0] < 412 && positionC < 180)
{
positionC++;
myServoC.write(positionC);
}
if(joystick[0] > 612 && positionC > 0)
{
positionC--;
myServoC.write(positionC);
}
if(joystick[1] < 412 && positionD < 150)
{
positionD++;
myServoD.write(positionD);
}
if(joystick[1] > 612 && positionD > 30)
{
positionD--;
myServoD.write(positionD);
}
}
if(ledOn3 == LOW)
{
if(joystick[2] < 412 && positionW < 180)
{
positionW++;
myServoW.write(positionW);
}
if(joystick[2] > 612 && positionW > 0)
{
positionW--;
myServoW.write(positionW);
}
if(joystick[3] < 412 && positionX < 180)
{
positionX++;
myServoX.write(positionX);
}
if(joystick[3] > 612 && positionX > 0)
{
positionX--;
myServoX.write(positionX);
}
}
if(ledOn3 == HIGH)
{
if(joystick[2] < 412 && positionY < 180)
{
positionY++;
myServoY.write(positionY);
}
if(joystick[2] > 612 && positionY > 0)
{
positionY--;
myServoY.write(positionY);
}
if(joystick[3] < 412 && positionZ < 180)
{
positionZ++;
myServoZ.write(positionZ);
}
if(joystick[3] > 612 && positionZ > 0)
{
positionZ--;
myServoZ.write(positionZ);
}
}
buttonState2 = joystick[4];
if (buttonState2 == HIGH && lastButton2 == LOW)
{
ledOn2 = !ledOn2;
lastButton2 = HIGH;
}
else
{
lastButton2 = buttonState2;
}
//digitalWrite(joystick[4], ledOn2);`Preformatted text`
digitalWrite(2, ledOn2);
digitalWrite(18, !ledOn2);
buttonState3 = joystick[5];
if (buttonState3 == HIGH && lastButton3 == LOW)
{
ledOn3 = !ledOn3;
lastButton3 = HIGH;
}
else
{
lastButton3 = buttonState3;
}
digitalWrite(3, ledOn3);
digitalWrite(19, !ledOn3);
}
}
}
}