I am searching for multi-threading or parallel programming with Arduino.
I have to operate two loops, the second loop has to start after the first one completes its 1/3rd process.
i googled and found that the usage of the millis() function in Arduino instead of using delay() function.
if you search for multi-thread in Arduino you will get that simple LED Blink tutorial for how to use this millis()
code instead of delay() which is very easy.
So if you want to learn some basics then go and google it.
before we start i am just beginner in Arduino i just know how to make for loop nad functions!
in this blog, I am going to demonstrate how to use that millions() function for making time delay between different operations.
as I said earlier I have to make a program in which there is two loop or operation in which second loop or operation starts after some time T and the first one starts immediately after starting the programme.
to keep this programme simple I have taken 2 servos in each loop. the first servo starts moving immediately after powering the Arduino and the second one starts after half a second passed. which means the second servo starts half second late after the first servo starts.
Programm is as following.
following programme is full of errors as am working on it i just thought that this will work but when i tested following code i not worked as expected.
so anyone who is smart enough to solve this kind of problem then just comment down below and let be know.
=========================================================================================================================================================================
#include<servo.h>
Servo s1;
Servo s2;
unsigned long pastMillis = 0;
const long diffrence = 500;
void setup()
{
s1.attach(10);
s2.attach(11);
}
void loop()
{
unsigned long timet= millis();
for(int x = 0 ; x<= 150 ; x++)
{
s1.write(x);
delay(10);
}
unsigned long ctime = time;
if(time-pastMillis >= diffrence)
{
for(int y =0; y<=150; y++)
{
s2.write(y);
delay(10);
}
}
}
"This site uses cookies from Google to deliver its services and analyze traffic. Your IP address and user-agent are shared with Google along with performance and security metrics to ensure quality of service, generate usage statistics, and to detect and address abuse."
I have to operate two loops, the second loop has to start after the first one completes its 1/3rd process.
i googled and found that the usage of the millis() function in Arduino instead of using delay() function.
if you search for multi-thread in Arduino you will get that simple LED Blink tutorial for how to use this millis()
code instead of delay() which is very easy.
So if you want to learn some basics then go and google it.
before we start i am just beginner in Arduino i just know how to make for loop nad functions!
in this blog, I am going to demonstrate how to use that millions() function for making time delay between different operations.
as I said earlier I have to make a program in which there is two loop or operation in which second loop or operation starts after some time T and the first one starts immediately after starting the programme.
to keep this programme simple I have taken 2 servos in each loop. the first servo starts moving immediately after powering the Arduino and the second one starts after half a second passed. which means the second servo starts half second late after the first servo starts.
Programm is as following.
following programme is full of errors as am working on it i just thought that this will work but when i tested following code i not worked as expected.
so anyone who is smart enough to solve this kind of problem then just comment down below and let be know.
=========================================================================================================================================================================
#include<servo.h>
Servo s1;
Servo s2;
unsigned long pastMillis = 0;
const long diffrence = 500;
void setup()
{
s1.attach(10);
s2.attach(11);
}
void loop()
{
unsigned long timet= millis();
for(int x = 0 ; x<= 150 ; x++)
{
s1.write(x);
delay(10);
}
unsigned long ctime = time;
if(time-pastMillis >= diffrence)
{
for(int y =0; y<=150; y++)
{
s2.write(y);
delay(10);
}
}
}
"This site uses cookies from Google to deliver its services and analyze traffic. Your IP address and user-agent are shared with Google along with performance and security metrics to ensure quality of service, generate usage statistics, and to detect and address abuse."
Comments
Post a Comment