Pages: 1 [2]   Go Down
Author Topic: [HELP] Running 2 programs at once.  (Read 1592 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now let's say that I wanted to take temperature readings and then control a servo motor independently.
What does this mean. You have one computer and two jobs. How can you expect to do them independently? Doing one right after the other (read the temps; diddle with the servo; read the temps; diddle with the servo) makes sense. Doing the two tasks independently requires two Arduinos. Help me understand what independently means to you.

My goal is like this, for example, a person is the MCU.

He is told to do 2 things, which is first, take temperature readings, and when a certain temperature is reached, he will do an action. The second, he has to tilt a servo motor every hour. Now I want to do these things in a combined manner. What I've noticed with the arduino is that, when it has finished taking temperature readings, it moves on to the servo part of the code, and that takes an hour to finish with the delay command that is involved. Now what if the temperature was reached and it couldn't detect it since it was on the servo part of the code.

That's what i'm trying to solve.

Maybe thermometer and servo are the independent parts?

Gin, loop() is your friend. Every time through can be 100 microseconds or less later, if your code doesn't hang things up. Inside loop() you can have a block of code that watches the sensor and the next block of code runs the servo. Each runs then loop() starts again and loop() is perpetually 'now'... but only if your code doesn't block.


So, after the void setup (), then the void loop (), i put another loop () and write my code in between?
Logged

--Gin319

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26186
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
after the void setup (), then the void loop (), i put another loop ()
No, you can't have two "loop"s.

You could write "loop1" and "loop2", and call them one after the other inside "loop"
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
after the void setup (), then the void loop (), i put another loop ()
No, you can't have two "loop"s.

You could write "loop1" and "loop2", and call them one after the other inside "loop"

Thanks for your reply.

Okay, now about the delay part, it would follow the sequence of the code on which action would be first? As the program runs by your suggestion, let's say for example, the servo control is on loop1 with a delay of let's say, 1 hour, then the thermometer is on loop2. Would the Arduino perform the 2 tasks independently?
Logged

--Gin319

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26186
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, don't use "delay".
Look at the blink without delay example to see how to eliminate "delay"
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: 1 [2]   Go Up
Jump to: