Hey,
so I wanted to send a value e.g. 160° from one arduino to another, so that the second arduino operates with that 160°. However I dont know how to do it and on the internet i cant seem to find any answers rlated to my problem.
My code so far:
Transmitter:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
bool radioNumber = 0;
int val = 90;
RF24 radio(9, 10); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(addresses[1]); // 00001
radio.openReadingPipe(1, addresses[0]); // 00002
radio.setPALevel(RF24_PA_LOW);
radio.stopListening();
}
void loop() {
if(Serial.available()){
val = Serial.parseInt();
}
Serial.println(val);
radio.write(val, sizeof(val));
delay(50);
}
Receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
int val = 160;
RF24 radio(2, 3); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
Servo myServo;
bool radioNumber = 1;
void setup() {
Serial.begin(9600);
myServo.attach(8);
radio.begin();
radio.openWritingPipe(addresses[0]); // 00002
radio.openReadingPipe(1, addresses[1]); // 00001
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
}
void loop() {
if ( radio.available()) {
radio.read(val, sizeof(val));
myServo.write(val);
Serial.println(val);
}
}