Skip to main content

Multi thread your Arduino

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."

Comments

Popular posts from this blog

Fix for installing GRUB on EFI System of KALI or Parrot os.

This fix will work on any linux Distro like KALI(debian) , Parrot OS(debian) ,Ubuntu etc. Having Problem while installing grub?  if your answer is yes then you are on right place. In this post i will guide through steps for fixing the GRUB error on EFI system with Windows on Dual boot. In this post i have not written about Installation steps. If you Don't Know about how to "dual boot with windows 10/8.1/8" then i request you to google about "How to dual boot?" why i am not doing so is because you will find very easy guide on Internet for Dual booting With Windows. The only Problem you will face when the installation is just going to finish, Boom!!! Error comes "Fail to create  Dummy GRUB" or ""Error While installing GRUB" or something Like that. I haven't faced any problem while installing "Kali rolling" on my system. When i start installing Kali on my friend's laptop at first the installation completes with suc

IMEI fix For MT6755/6753 Lenovo K5 note

IMEI FIX FOR MT6755/6753 Lenovo k5 note   you can watch above video or continue following description  If you do not want to read this story then skip this i have written the Fix for Lenovo K5 note or MT6755 and MT 6753 in this post after the story.   My friend bought Lenovo k5 note a month ago and he tried to change the LTE band to band 4 0 using android MTK engineering mode. After he restarted phone IMEI got lost and NVRAM WARNING: Err = 0x10 comes up. After so he contacted the Lenovo Care. At Lenovo care they told my fried to change the Chip which is cost around 8000/-(INR) my friend refused to do same. And then he asked me to repair his Lenovo K5 note. The same thing is happened with me with my Lenovo K4 note , but in my case i have accidentally  selected Format All+ Download in SP flash tool . I tried to fix for 2 days after that i gave up and took my phone to nearest mobile repair Shop. They fixed IMEI but not able to fix NVRAM WARNING : Err= 0x1

Compile Custom Rom From Source

Compiling custom rom from source code. Compiling custom rom takes a hell lot of time!!!! so be aware of That! First things first you have to setup system to start compiling. you have to be on Ubuntu Os. You can use virtual box or dual boot with windows(the best option) System requirements for fastest compilation are as below: Important minimum 8GB of RAM ( you're compiling rom based on Marshmallow or Nougat) 100GB of free Space on HDD (it is good to have a SSD). Quad Core processor. A good internet connection with unlimited data yeah that's it! my suggestion is that you have to install Ubuntu alongside you system means dual boot! (why ? ask yourself!). now, I am assuming that you have installed and boot up in Ubuntu. So let's Get Started! Step 1 :- install JAVA (open jdk 8) in Ubuntu. open up the terminal and type the following command and hit enter. $ sudo apt-get install openjdk-8-jdk Step 2 :- Install other packages