Start Stop and threads

I need some help with programming. I am currently running on some sort of threads on the arduino UNO.

I will have a LED which displays Play(LED ON), Pause(LED Blinking), STOP(LED OFF)

Signals are via the serial port.

Firstly, I will be running some eccentric motor by analogwrite(). But it is run via a sequence of about 40 lines.
In the midst of Playing the program, the LED will be ON and the motor will be running.
While I press pause, the program is to hold there and the LED is to start blinking to signal pause
as I press play the program will run back where it was hold and continue from there.

Can I know which function can help me from doing multiple programs yet able to hold the sequence there

Thanks in advance

 #include <Thread.h>
#include <ThreadController.h>

int ledPin = 13;
int ledState = LOW;
long previousMillis = 0;
long interval = 1000;


Thread Thread1 = Thread();
Thread Thread2 = Thread();
Thread Thread3 = Thread();

char getData;
boolean Datatransfer;
boolean Flag1;

void blinking(){
 unsigned long currentMillis = millis();
 if(currentMillis - previousMillis > interval) 
 {
    previousMillis = currentMillis;   
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
      digitalWrite(ledPin, ledState);
  }
}


void Comms(){
  while(Serial.available()){
    getData = Serial.read();
    if(getData=='1'){
    Datatransfer = false;
    Flag1 = true;
    digitalWrite(ledPin,HIGH);
    }
    else if (getData=='2'){
    Datatransfer = true;
    Flag1=false;
    }
    else if (getData=='3'){
    digitalWrite(ledPin,LOW);
    Datatransfer = false;
    Flag1=false;
    }
    else;
    Serial.flush();
  }
}

void setup() 
{ 
  pinMode(6, OUTPUT);           //set pin 7 as output (Reset)
  pinMode(13,OUTPUT);
  
  Thread1.onRun(blinking);
  Thread1.setInterval(500);
  
  Thread2.onRun(Comms);
  Thread2.setInterval(10);
  
  Thread3.onRun(mainprogram);
  Thread3.setInterval(250);
  
 
  Serial.begin(9600);    	//initialize serial
}

void v255()
{
  analogWrite(6, 255);
}
void v200()
{
  analogWrite(6, 200);
}
void v150()
{
  analogWrite(6, 150);
}
void v100()
{
  analogWrite(6, 100);
}
void v255f()
{
  analogWrite(6, 255);
}
void v200f()
{
  analogWrite(6, 200);
}
void v150f()
{
  analogWrite(6, 150);
}
void v100f()
{
  analogWrite(6, 100);
}
void v255b()
{
  analogWrite(6, 100);    // stop transmitting
}
void v200b()
{
  analogWrite(6, 100);
}
void v150b()
{
  analogWrite(6, 100);
}
void v100b()
{
  analogWrite(6, 100);
}
void v255r1()	              // Res 255 at row 1
{
  analogWrite(6, 100);
}
  void v200r1()		      // Res 200 at row 1
{
  analogWrite(6, 100);
}
void v150r1()		      // Res 150 at row 1
{
  analogWrite(6, 100);
}
void v100r1()		      // Res 100 at row 1
{
  analogWrite(6, 100);
}
void v255r2()		      // Res 255 at row 2
{
  analogWrite(6, 100);
}
void v200r2()		      // Res 200 at row 2
{
  analogWrite(6, 100);
}
void v150r2()		      // Res 150 at row 2
{
  analogWrite(6, 100);
}
void v100r2()		      // Res 100 at row 2
{
  analogWrite(6, 100);
}
void v255r3()		      // Res 255 at row 3
{
  analogWrite(6, 100);
}
void v200r3()		      // Res 200 at row 3
{
  analogWrite(6, 100);
}
void v150r3()		      // Res 150 at row 3
{
  analogWrite(6, 100);
}
void v100r3()		      // Res 100 at row 3
{
  analogWrite(6, 100);
}
void off()
{
  analogWrite(6, 0);
}

void mainprogram()
{
  if(Flag1==true)
  {
  v100();
  delay(1000);
  off();
  delay(11300);
  v200();
  delay(200);
  off();
  delay(33);
  v200();
  delay(200);
  off();
  delay(67);
  v200();
  delay(200);
  off();
  delay(167);
  v200();
  delay(200);
  off();
  delay(467);
  v150();
  delay(200);
  off();
  delay(133);
  v200();
  delay(200);
  off();
  delay(1300);
  v200();
  delay(200);
  off();
  delay(333);
  v200();
  delay(200);
  off();
  delay(133);
  v200();
  delay(200);
  off();
  delay(100);
  v200();
  delay(200);
  off();
  delay(4133);
  v255();
  delay(2867);
  off();
  delay(600);
  v200();
  delay(333);
  off();
  delay(11067);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(100);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(100);
  off();
  delay(100);
  v255();
  delay(100);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(100);
  v255();
  delay(200);
  off();
  delay(6367);
  v255();
  delay(533);
  v150();
  delay(1400);
  v255();
  delay(633);
  v150();
  delay(1167);
  v255();
  delay(633);
  v150();
  delay(700);
  v255();
  delay(900);
  v150();
  delay(1200);
  v255();
  delay(500);
  v150();
  delay(1600);
  v255();
  delay(467);
  v150();
  delay(400);
  v255();
  delay(467);
  v150();
  delay(133);
  off();
  delay(300);
  v200();
  delay(400);
  off();
  delay(233);
  v200();
  delay(667);
  off();
  delay(12300);
  v255();
  delay(1033);
  v150();
  delay(200);
  off();
  delay(2500);
  v100();
  delay(1900);
  off();
        }
        else;
  }
        
void loop()
{
  Thread2.run();
  Thread3.run();
  if (Datatransfer==true)
  Thread1.run();
  else;
}

I am currently running on some sort of threads on the arduino UNO.

The Arduino doesn't do threads.

Can I know which function can help me from doing multiple threads yet able to hold the sequence there

There aren't any.

Post your code, so we have some idea what you are talking about.

Please edit you post and put the code in code tags (the # button) so we can follow it more easily.

What are you trying to do? Why did you think you would need threads? That seems a very complicated way to do things on a little ol' Arduino.

...R

You obviously haven’t read the instructions at the top of the forum and you haven’t taken any notice of my earlier post.

Put your code in code tags using the #button at the top of the edit window!

Explain what you are trying to do in english without code. I’m not going to try to understand your lengthy code when I have no idea what it is supposed to achieve and while it is not formatted properly.

…R

frozen29:
Can I know which function can help me from doing multiple threads yet able to hold the sequence there

It’s not a function as such, but a way of designing your sketch. You need to use a non-blocking approach so that the sketch can control multiple things concurrently and independently. The blink without delay example gives a simple demonstration of handling timed events in a non-blocking way.

OP POSTED CODE ON SECOND THREAD

look for the code on the other thread of the exact same subject line.

Thanks Dave...Do you have the link for it?

This is very confusing @frozen29. You seem to have deleted a post that I replied to and you seem to have amended your first post so it bears little relation to what it was originally.

It is easy for everyone to follow the discussion if you leave earlier posts as they were, apart from formatting code to make it readable.

It is especially confusing when you seem to be asking for a link to your own post

Thanks Dave...Do you have the link for it?

As @PeterH has said the technique in the "blink without delay" example (which comes with the Arduino IDE) should enable you to do what you want without the complexity of "pseudo" threads.

...R