I have been working on making a 12 channel transmitter and receiver for a project and I can't seem to get my codes to work. it worked the other day but I made some tweaks and it seized to function. Unfortunately I can't remember the changes I made to the code so I'm stuck. Anny help would be much appreciated. Here are the codes.
Transmitter:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10);
struct MyData {
int state0;
int state1;
int state2;
int state3;
int state4;
int state5;
int state6;
int state7;
int state8;
int state9;
int state10;
int state11;
};
MyData data;
void resetData() {
data.state0 = 0;
data.state1 = 0;
data.state2 = 0;
data.state3 = 0;
data.state4 = 0;
data.state5 = 0;
data.state6 = 0;
data.state7 = 0;
data.state8 = 0;
data.state9 = 0;
data.state10 = 0;
data.state11 = 0;
}
const byte address[6] = "00001";
const int CH0 = A0;
const int CH1 = A1;
const int CH2 = A2;
const int CH3 = A3;
const int CH4 = A4;
const int CH5 = 2;
const int CH6 = 3;
const int CH7 = 4;
const int CH8 = 5;
const int CH9 = 6;
const int CH10 = 7;
const int CH11 = 8;
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
pinMode(CH0, INPUT);
pinMode(CH1, INPUT);
pinMode(CH2, INPUT);
pinMode(CH3, INPUT);
pinMode(CH4, INPUT);
pinMode(CH5, INPUT_PULLUP);
pinMode(CH6, INPUT_PULLUP);
pinMode(CH7, INPUT_PULLUP);
pinMode(CH8, INPUT_PULLUP);
pinMode(CH9, INPUT_PULLUP);
pinMode(CH10, INPUT_PULLUP);
pinMode(CH11, INPUT_PULLUP);
}
void loop() {
data.state0 = analogRead(CH0);
data.state1 = analogRead(CH1);
data.state2 = analogRead(CH2);
data.state3 = analogRead(CH3);
data.state4 = analogRead(CH4);
data.state5 = digitalRead(CH5);
data.state6 = digitalRead(CH6);
data.state7 = digitalRead(CH7);
data.state8 = digitalRead(CH8);
data.state9 = digitalRead(CH9);
data.state10 = digitalRead(CH10);
data.state11 = digitalRead(CH11);
radio.write (&data, sizeof(MyData));
delay(1);
}
Receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
Servo CH0;
Servo CH1;
Servo CH2;
Servo CH3;
Servo CH4;
const int CH5 = A0;
const int CH6 = 2;
const int CH7 = 4;
RF24 radio(7, 8); //(CE, CSN)
const byte address[6] = "00001";
struct MyData {
int state0;
int state1;
int state2;
int state3;
int state4;
int state5;
int state6;
int state7;
int state8;
int state9;
int state10;
int state11;
};
MyData data;
void resetData() {
data.state0 = 0;
data.state1 = 0;
data.state2 = 0;
data.state3 = 0;
data.state4 = 0;
data.state5 = 0;
data.state6 = 0;
data.state7 = 0;
data.state8 = 0;
data.state9 = 0;
data.state10 = 0;
data.state11 = 0;
}
void setup() {
radio.begin();
radio.openReadingPipe(0, address[6]);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Serial.begin(9600);
CH0.attach(3);
CH1.attach(5);
CH2.attach(6);
CH3.attach(9);
CH4.attach(10);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
}
void loop() {
if (radio.available()) {
radio.read(&data, sizeof(MyData));
}
int CH0val = map(data.state0, 0, 1023, 0, 180);
int CH1val = map(data.state1, 0, 1023, 0, 180);
int CH2val = map(data.state2, 0, 1023, 0, 180);
int CH3val = map(data.state3, 0, 1023, 0, 180);
int CH4val = map(data.state4, 0, 1023, 0, 180);
int CH5val = data.state5;
int CH6val = data.state6;
int CH7val = data.state7;
int CH8val = data.state8;
int CH9val = data.state9;
int CH10val = data.state10;
int CH11val = data.state11;
CH0.write(CH0val);
CH1.write(CH1val);
CH2.write(CH2val);
CH3.write(CH3val);
CH4.write(CH4val);
if (CH5val == 0) {
digitalWrite(2, HIGH);
}
else {
digitalWrite(2, LOW);
}
if (CH6val == 0) {
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
if (CH7val == 0) {
digitalWrite(A0, HIGH);
}
else {
digitalWrite(A0, LOW);
}
if (CH8val == 0) {
digitalWrite(A1, HIGH);
}
else {
digitalWrite(A1, LOW);
}
if (CH9val == 0) {
digitalWrite(A2, HIGH);
}
else {
digitalWrite(A2, LOW);
}
if (CH10val == 0) {
digitalWrite(A3, HIGH);
}
else {
digitalWrite(A3, LOW);
}
if (CH11val == 0) {
digitalWrite(A4, HIGH);
}
else {
digitalWrite(A4, LOW);
}
}