How can I run multiple void loops that do not depend on each other
like there
thank you
How can I run multiple void loops that do not depend on each other
like there
thank you
Simply, you can't
Have a look at Several things at the same time (Google).
Here is the link (Demonstration code for several things at the same time - Project Guidance - Arduino Forum) mentioned in Septillion's comment.
damir27:
please help
You've been helped. Now what do you need?
example
i wont that do not depend on each other ,
the problem is that the first segment goes one then the other
int latchPin = 2; //pin 12 on the 595
int dataPin = 3; //pin 14 on the 595
int clockPin = 4; //pin 11 on the 595
int pin1 = 5; //pin 12 on the 595
int pin2 = 6; //pin 14 on the 595
int pin3 = 7;
void setup() {
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
//0
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 64);
digitalWrite(latchPin, HIGH);
delay(1000);
//1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 121);
digitalWrite(latchPin, HIGH);
delay(1000);
//2
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 36);
digitalWrite(latchPin, HIGH); delay(1000);
//3
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 48);
digitalWrite(latchPin, HIGH); delay(1000);
//4
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 25);
digitalWrite(latchPin, HIGH);
delay(1000);
//5
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 18);
digitalWrite(latchPin, HIGH);
delay(1000);
//6
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 2);
digitalWrite(latchPin, HIGH);
delay(1000);
//7
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 120);
digitalWrite(latchPin, HIGH);
delay(1000);
//8
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0);
digitalWrite(latchPin, HIGH);
delay(1000);
//9
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 24);
digitalWrite(latchPin, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 64);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2,pin3, MSBFIRST, 121);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 36);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 48);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 25);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 18);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 2);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 120);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 0);
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
shiftOut(pin2, pin3, MSBFIRST, 24);
digitalWrite(pin1, HIGH);
delay(1000);
}
Yes, that's how you have it coded. To run them one after the other. That's what you get when you use delay for timing. Now read the link you were given above. It explains how to handle your timing so that you can do what you want. If you can't be bothered to at least read it then I don't see why we should be bothered to try to help you any further.
How can I run multiple void loops that do not depend on each other
like there
Those loops (loop2() and loop3() ) are just names for functions, controlled by the scheduler library.
Nothing else.
They could also have been named function2 and function 3 ...
It's simply like @Septillion said:
Simply, you can't
Have a look at the link, which was already cited in the previous posts, and that's what is the only possibility for doing things (almost) at the same time in several "loops" / functions:
http://forum.arduino.cc/index.php?topic=223286.0
Please use code tags (</> button on the toolbar) when you post code or warning/error messages.
Please do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.
Read an understand the "blink without delay" example. Then read and understand "several things at the same time".
The method for doing what you want is that you never use delay(). Instead, your sketch tracks state in some global variables, and uses millis() to decide when to change state. If you have two things that do this, then the main loop() simply gives each of them a turn.
I like to enclose things in classes, myself, but the method works equally well by simply giving everything names that don't collide. Classes work especially well when you have two almost identical things such as what you appear to have here.
Please read your PM
Have a look at one of the library I created, internally it uses millis to handle function call. This library is based on Timer library but modified to meet my requirements.
Robin2:
Have a look at the demo Several Things at a Time...R
I already provided that link (copied from one of your previous post), seems like OP didnt bother looking into it.
sarouje:
I already provided that link (copied from one of your previous post), seems like OP didnt bother looking into it.
Sorry, and thanks. I missed that. I only saw the reference to it without the link.
...R
Get a separate Arduino for each function you want to run independently.
Or read the help that was already provided.
Rethink the problem as if you were let into a room with some lights (inputs), some switches (outputs) along with a clock, pencil & paper. You can start with any notes you'd like already on the paper (setup() but you only get say.. 1 minute to jot down what you need and flip whatever switches you need. Then you must run out of the room, turn around and run back.
run into the room, paper says blink on 5 minutes off 5 minutes. What do you do?
Simple look at the clock;
write down the time, flick on the light;
calculate the time the light should go off;
write that time down on the paper..;
RUN out of room!;
The next few times you run through the room you look at the clock but there's nothing to do, run out again!
At some point you run in
read the paper;
look at the clock;
and see it's time to shut off the light, What would you do?
-jim lee
jimLee:
Rethink the problem as if you were let into a room with some lights (inputs), some switches (outputs) along with a clock, pencil & paper. You can start with any notes you'd like already on the paper (setup() but you only get say.. 1 minute to jot down what you need and flip whatever switches you need. Then you must run out of the room, turn around and run back.run into the room, paper says blink on 5 minutes off 5 minutes. What do you do?
Simple look at the clock;
write down the time, flick on the light;
calculate the time the light should go off;
write that time down on the paper..;
RUN out of room!;The next few times you run through the room you look at the clock but there's nothing to do, run out again!
At some point you run in
read the paper;
look at the clock;
and see it's time to shut off the light, What would you do?-jim lee
Or take a closer look at the code which outputs 8 bits in a sequence (shiftOut) and than stops for a time determined by a delay.
Where are the "multiple void loops" ? These are single events separated by delays so far.
Noting to turn on, go get a drink, and than turn it off.
There is a communication / terminology gap which needs to be bridged first.
Jim
julyjim:
Or take a closer look at the code which outputs 8 bits in a sequence (shiftOut) and than stops for a time determined by a delay.Where are the "multiple void loops" ? These are single events separated by delays so far.
Noting to turn on, go get a drink, and than turn it off.There is a communication / terminology gap which needs to be bridged first.
Jim
You're trying to force calculus into a kindergartner.
-jim lee
I guess I bow-out and let the experts figure it out.
julyjim:
I guess I bow-out and let the experts figure it out.
Now now, it's usually the experts that end up trying that.
I looked at the original post and thought. "He has no idea about how to run stuff concurrently, this is why he's in this dilemma." At this point everyone wants to jump in with the "blink without delay" answer. I'm betting at that point this is just more confusion. That's why I tried it as a parable. Trying to shift his basic thinking about how to approach the problem.
But maybe I'm trying to force english lit. into a kindergartner..
That's the thing about the internet, everyone's wrong.
-jim lee