Alright, I had a little help and we came up with this code.
I know its not perfect because it should be using an array but it does the Job. Still need some modifications though.
//transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10);
const byte rxAddr[6] = "00001";
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setRetries(15, 15);
radio.openWritingPipe(rxAddr);
radio.stopListening();
}
void loop()
{
while( Serial.available()>0){
char cmd = Serial.read();
if (cmd > 48 && cmd < 57){
radio.write(&cmd, 1);
}
}
}
//receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CH1 2
#define CH2 3
#define CH3 4
#define CH4 5
RF24 radio(9, 10);
char cmd;
const byte rxAddr[6] = "00001";
void onPin(int8_t pin) {
digitalWrite(pin, LOW);
delay(1000);
digitalWrite(pin, HIGH);
}
void offPin(int8_t pin) {
digitalWrite(pin, HIGH);
}
void setup()
{
pinMode(CH1, OUTPUT);
pinMode(CH2, OUTPUT);
pinMode(CH3, OUTPUT);
pinMode(CH4, OUTPUT);
digitalWrite(CH1,HIGH);
digitalWrite(CH2,HIGH);
digitalWrite(CH3,HIGH);
digitalWrite(CH4,HIGH);
radio.begin();
radio.openReadingPipe(0, rxAddr);
radio.startListening();
}
void loop()
{
if (radio.available())
{
radio.read(&cmd, 1);
switch(cmd){
case '1': onPin(CH1); break;
case '2': onPin(CH2); break;
case '3': onPin(CH3); break;
case '4': onPin(CH4); break;
case '5': offPin(CH1); break;
case '6': offPin(CH2); break;
case '7': offPin(CH3); break;
case '8': offPin(CH4); break;
}
}
}
Basically just 1-4 to turn on relay 1-4 and 5-8 to turn relay 1-4 off again.
...not quite what I wanted but itll do for now.
Thanks for your input, I might be back soon..![]()