I want arduino to wait until it receives 1800 us pulse from my receiver. Anyone can suggest me the logic for that? which loop should I use?
I am programming for my Quadcopter flight controller and want to calibrate my ESC when program starts. I want to do it when I signal from my transmitter.
thanks
yes. I have seen that. but this is not I actually desire. I want to trigger my all code when arduino receives 1900us signal from channel 4. pulseIn will not hold the execution of rest of code for me.
yes. I have seen that. but this is not I actually desire. I want to trigger my all code when arduino receives 1900us signal from channel 4. pulseIn will not hold the execution of rest of code for me.
If you are able to send a 1900 us pulse, why is max_high_time set to 1895?
Which channel is the 1900us pulse going to arrive on?
Of course pulseIn() BY ITSELF won't wait. YOU have to write code to end setup() when the appropriate length pulse arrives on the appropriate channel.
By the way, mixing interrupts and pulseIn() seems pointless. Which ONE do you want to use?
I said 1900us in rounded figures. and the purpose of mixing interrupts and pulseIn is to use all 6 channels. I am using Arduino Mega 2560 btw. which have 6 interrupts. 2 of 'em being used by MPU6050 as SDA and SCL pins.I am left with 4 interrupts, which I am using for 4 channels. Rest of 2 channels are being read by PulseIn which I will use for triggering my camera module or something like that. Right now I just want to make arduino wait until it receives a high pulse on particular channel. I want to do it by internal interrupts if it is possible
What you describe does not sound hard but maybe I have misunderstood.
Just stay in a while loop in setup() until the condition you are looking for occurs. Where is the problem ?
I am calibrating my ESC with the short code I have written.
#include <Servo.h>
#define MAX_SIGNAL 2100
#define MIN_SIGNAL 900
#define esc1 5//front right
#define esc2 6//back right
#define esc3 7//front left
#define esc4 8//back left
Servo firstESC,secESC,thirdESC,forthESC;
void setup() {
Serial.begin(115200);
Serial.println("Program begin...");
Serial.println("This program will calibrate the ESC.");
firstESC.attach(esc1);
secESC.attach(esc2);
thirdESC.attach(esc3);
forthESC.attach(esc4);
Serial.println("Now writing maximum output.");
Serial.println("Turn on power source, then wait 2 seconds and press any key.");
firstESC.writeMicroseconds(MAX_SIGNAL);
secESC.writeMicroseconds(MAX_SIGNAL);
thirdESC.writeMicroseconds(MAX_SIGNAL);
forthESC.writeMicroseconds(MAX_SIGNAL);
// Wait for input
while (!Serial.available());
Serial.read();
// Send min output
Serial.println("Sending minimum output");
firstESC.writeMicroseconds(MIN_SIGNAL);
secESC.writeMicroseconds(MIN_SIGNAL);
thirdESC.writeMicroseconds(MIN_SIGNAL);
forthESC.writeMicroseconds(MIN_SIGNAL);
}
void loop() {
}
Yes its not that difficult as you said but I am unable to find proper logic for that condition.
Talking about while loop, according to my understandings, it keeps executing a code inside it until a specific condition is not true. I want to run this code when I press the button from my transmitter or you can say when arduino receives a signal of 1895us on channel 4. I want to run my code for once.
Talking about while loop, according to my understandings, it keeps executing a code inside it until a specific condition is not true.
Or until the specified condition is true. So, what IS the condition that should cause the while loop to end?
while(someValue < someThreshold)
{
// Do nothing but check again
someValue = ???;
}
This code would spin while someValue, however it is defined, is less than someThreshold (presumably 1900 in your case). Each time through the loop, it will get a new value for someValue, by whatever method you define.
When the while loop ends, because someValue is greater than, or equal, someThreshold, calibrate the ESC and then let setup() end, so loop() can begin.