How can I run two loops or processes at the same time? I'm trying to separate two different processes so they don't interfere with each other. Here's an example:
I'm not sure as to how I can have both of these two commands function properly at the same time, as the arduino doesn't seem to like the fact that there are two 'void loop()' statements. Thanks for the help!
Poor delay function, so misunderstood and misused, it just wants to have a place in the tool box for those that might better appreciate it. It's like the old saying if all you have (or understand) is a hammer it's amazing how everything tends to look like a nail.
Poor delay function, so misunderstood and misused, it just wants to have a place in the tool box for those that might better appreciate it. It's like the old saying if all you have (or understand) is a hammer it's amazing how everything tends to look like a nail.
Can't argue with anything there. My only comment would be that it would be nice to see the blink without delay improved a bit, and presented BEFORE the blink with delay example. It's the first tools that are presented/learned/acquired that are the most used. Knowing first how NOT to use delay() would make people aware that delay() has side effects that can, and often must, be avoided.
Hello all ,
I just wrote a bit of code that solves your problem directly. You can see this right on the Arduino reference section. But it is rather hard to find. So I can't blame you. And I'm not. But think about making a variable.
Here's a link to the page, and a snippet of my code. http://www.arduino.cc/en/Reference/FunctionDeclaration
void loop()
// note that this is the most basic of navigation systems… it uses a simplistic method for navigation…. needs improvement.
{
int sensor = AquireDist();
DriveR.write(360);
DriveL.write(-360);
if(sensor < forwardThreshold)
{
DriveR.write(-360);
DriveL.write(360);
delay(2500);
DriveR.write(360);
DriveL.write(360);
delay(3000);
}
}
int AquireDist() // this can be used with any digital in/out sonar type distance sensor (PWM).
{
const int sensor = 7;
int duration;
pinMode(sensor, INPUT);
//ping…(wait for the pong)
pinMode(sensor, OUTPUT);
digitalWrite(sensor, LOW);
delayMicroseconds(2);
digitalWrite(sensor, HIGH);
delayMicroseconds(5);
digitalWrite(sensor, LOW);
//listening for pong now
pinMode(sensor, INPUT);
duration = pulseIn(sensor, HIGH);//PpPpPOoOoOnnnnnnng(hopefully) Serial.println(duration / 29 / 2 ); // for debugging
return duration / 29 / 2 ;//convert to a human number with a unit...
}
Is an odd way of achieving DriveL.write(0);
because
void Servo::write(int value)
{
if(value < MIN_PULSE_WIDTH)
{ // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
if(value < 0) value = 0;
if(value > 180) value = 180;
value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX());
}
this->writeMicroseconds(value);
}
Judging from this poster's recent posts, I think we have either:
a) a bot (unlikely)
b) a spammer
c) an idiot.
d) someone trying to bump their post stats.
It's a continuous rotation servo. The only way I know of to reverse it is to write a negative value to it.
Also, that is not the point that I attempted to get across. My point was to show that you can run two functions simultaneously and continuously without the use of for( , , ). Sorry if that wasn't clear.
The link I showed uses this method, where int AquireDist() is the other function. It's like naming an integer/ variable, except that is the form of value it returns. I don't know if you checked the link I provided, but that was supposed to explain the code example.
The link I showed uses this method, where int AquireDist() is the other function
One of us is missing the point of what the OP was trying to do.
My take was that they were trying to run two tasks or processes concurrently (not simultaneously - that would be impossible on a single core processor), your take seems to be how to call a function consecutively.
Oh I see what you mean. Sorry about the confusion. You are absolutely correct. I am calling a function, while this post was about running another concurrent process. Now I see my mistake.