I have been trying for hours to create the correct code and cannot figure out how.
I am successfully transmitting servo position and successfully control an servo. What I want to do is be able to turn off the servo with a relay when they is no RF being received. I have been experimenting with just the onboard led to simulate the control of a relay.
What code do I add to simply turn on a LED when there is no data being received?
forgot also the code tags...Please correct your post above and add code tags around your code: [code]`` [color=blue]// your code is here[/color] ``[/code].
It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)
so you did not answer how you'll decide that no message is being received? is it OK to turn on a LED 1 microsecond after you received a message since there is no new message? or may be it's better to say "if I did not receive a message for 10 seconds, then turn on the LED"? --> millis() will help you solve that
Just learning this forum. Thanks tips for the how to enter the code.
I like "if I did not receive a message for 10 seconds, then turn on the LED"? --> millis() will help you solve that.
I am not familiar with millis() where would this go and how do I set this up?
//code #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #include <Servo.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
Servo myServo;
int servo;
void setup() {
myServo.attach(5);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
}
void loop() {
if (radio.available()) {
//while (radio.available()) {
int angleV = 0;
radio.read(&angleV, sizeof(angleV));
myServo.write(angleV);
Serial.println(angleV );
}
}
Save the value of millis() each time you receive a message successfully
Each time through loop() check whether the current value of millis() minus the save value is greater than 10 seconds. If so, then you have not received a message for 10 seconds so take any necessary action