Hi, I have estabelished a communication between two arduino pro mini boards using NRF24L01 chip on each arduino. First arduino is sending 3 potentiometer values. The second arduino is receiving those values and controlling 3 colors (RGB) on the RGB LED strip.
The problem is that the color isn't stable (three values are mixing and switching places) e.g. I turn on the red color and after a couple of minutes/seconds it changes to green or it just turns off and quickly turns on.
TRANSMITTER code:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int red[1];
int green[1];
int blue[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop(){
red[0] = analogRead(A1) / 4;
green[0] = analogRead(A2) / 4;
blue[0] = analogRead(A3) / 4;
radio.write(red, sizeof(red));
radio.write(green, sizeof(green));
radio.write(blue, sizeof(blue));
}
RECEIVER code:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int red[1];
int blue[1];
int green[1];
int redVal;
int blueVal;
int greenVal;
int redOut = 3;
int blueOut = 5;
int greenOut = 6;
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup() {
Serial.begin(9600);
pinMode (redOut, OUTPUT);
pinMode (blueOut, OUTPUT);
pinMode (greenOut, OUTPUT);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();
}
void loop() {
if (radio.available()) {
radio.read(red, sizeof(red));
radio.read(blue, sizeof(blue));
radio.read(green, sizeof(green));
Serial.println(red[0]);
Serial.println(blue[0]);
Serial.println(green[0]);
int redVal = red[0];
int blueVal = blue[0];
int greenVal = green[0];
analogWrite(redOut, red);
analogWrite(blueOut, blue);
analogWrite(greenOut, green);
}
}