I am making a rocket with a motor and propellor. It will be remote controlled by a potentiometer on a remote controll and the messages will be sent by nrf24lo1+ modules.
Could someone run through my code to if if anything is drastically wrong with it?
I really dont want to break anything and any help would be much appreciated.
Many thanks,
Jethro.
Transmitting end code:
#include
#include
#include
RF24 radio(9, 10); // CE, CSN
const uint64_t pipe = 0xE8E8F0F0E1LL;
int potPin = A0; // Potentiometer pin
int throttleValue = 0; // Value to send over radio
void setup() {
radio.begin();
radio.openWritingPipe(pipe);
}
void loop() {
// Read the analog value of the potentiometer
throttleValue = analogRead(potPin) / 4; // Scale it to a value between 0-255
// Send the value over the radio
radio.write(&throttleValue, sizeof(throttleValue));
delay(10); // Wait a short amount of time before sending again
}
Receiving end code:
#include
#include
#include
#include
RF24 radio(9, 10); // CE, CSN
const uint64_t pipe = 0xE8E8F0F0E1LL;
Servo esc; // Servo object for controlling the ESC
void setup() {
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();
esc.attach(3); // Set up the ESC on pin 3
}
void loop() {
if (radio.available()) {
int throttleValue = 0;
radio.read(&throttleValue, sizeof(throttleValue)); // Receive the value over radio
esc.write(throttleValue); // Set the ESC speed to the received value
}
}