Can arduino uno multitasking ?

Hi all,
I have 2 Arduino programs that are rotary encoder and buzzer alarm every 4 hours, and I want to run 2 programs on 1 Arduino Uno board. the question is:

  1. Can Arduino do multitasking 2 programs running at the same time?

I tried to combine the two programs but the only one that can run the Buzzer alarm program per 4 hours, and immediately the rotary encoder cannot run, is there a problem with the Arduino timer, since both programs require a timer, please advise,

thank you

2 programs, no. Multitask two simple tasks you propose, easy. Only think to not do is block the Arduino anywhere. In practice that means no delay() ANYWHERE. Use millis() to do all the timing.

I tried to combine the two programs

Please post your combined program

#define encoder0PinA 2
#define encoder0PinB 4
#include <LiquidCrystal.h>

unsigned int encoder0Pos=0;
int newposition;
int oldposition;
int newtime;
int oldtime;
float kecepatan;
//float speed;
LiquidCrystal lcd (5, 6, 7, 9, 10,11);

void speedBuzzer(int waktu);
const int pinBuzzer = 13;
int ulang = 0;
// the setup function runs once when you press reset or power the board

int runTimer = 1;
int runFor = 60; // timer

void setup()
{
lcd.begin(16, 2);
pinMode(encoder0PinA, INPUT);
digitalWrite(encoder0PinA, HIGH); // turn on pullup resistor
pinMode(encoder0PinB, INPUT);
digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor
attachInterrupt(0, doEncoder, RISING); // encoDER ON PIN 2
Serial.begin (9600);
Serial.println(“start”); // a personal quirk
lcd.print (" RPM");
lcd.setCursor(2,0);
pinMode (8, OUTPUT);

pinMode(pinBuzzer, OUTPUT);
}

void loop()
// 6 sama dengan jumlah baut
{
newposition = encoder0Pos;
newtime = (0.001millis());
kecepatan = (newposition-oldposition)
(newtime-oldtime); // 6 sama dengan jumlah baut
//speed = kecepatan;
fungsi();
delay(10);
buzzer();

}

void doEncoder()
{
if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
encoder0Pos++;
} else {
encoder0Pos–;
}

// Serial.println (encoder0Pos, DEC);
}

void fungsi()
{
if (kecepatan >= 2)
// Serial.print (“unloading”);
//lcd.print (“unloading”);
//lcd.setCursor(2,0);
digitalWrite (8, HIGH);
else
digitalWrite (8,LOW);

if (kecepatan <= -1)
// Serial.print (“loading”);
//lcd.print(" loading");
// lcd.setCursor(2,0);
//digitalWrite (13, HIGH);
//else
//digitalWrite (13,LOW);

Serial.print ("\n speed = “);
Serial.println (kecepatan);
lcd.setCursor(0,0);
lcd.print ((kecepatan)); // ini tampilanya
//lcd.setCursor (0,1);
//lcd.print (” jumlah baut 6");
oldposition = newposition;
oldtime = newtime;
delay(1000);
}

void buzzer()
{
runTimer = 0;
delay(5400000); //testing alarm menyala dalam 1jam 30 menit
for ( ulang = 0; ulang < 20; ulang++){
speedBuzzer(250);// peringatan pertama bunyi beep 5x dengan delay waktu 250ms
}
for ( ulang = 0; ulang < 20; ulang++){
speedBuzzer(500);//peringatan pertama bunyi beep 5x dengan delay waktu 500ms
}
delay(1800000); //testing delay waktu untuk peringatan kedua dengan waktu tunda 30menit setelah peringatan pertama
for ( ulang = 0; ulang < 30; ulang++){
speedBuzzer(250);// peringatan kedua bunyi beep 10x dengan delay waktu 250ms
}
for ( ulang = 0; ulang < 30; ulang++){
speedBuzzer(500); // peringatan kedua bunyi beep 10x dengan delay waktu 500ms
}
}
void speedBuzzer(int waktu){
digitalWrite(pinBuzzer,HIGH);
delay(waktu);
digitalWrite(pinBuzzer,LOW);
delay (waktu);
}

 delay(1800000);  //do nothing for 30 minutes

No wonder there is a problem

Read and understand Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

septillion:
2 programs, no. Multitask two simple tasks you propose, easy. Only think to not do is block the Arduino anywhere. In practice that means no delay() ANYWHERE. Use millis() to do all the timing.

thanks for the advice,

I got the multitasking.h library on the Arduino IDE,
can he work like
task1 (do program 1)
task2 (do program 2)
all run in 1 program sketch?

I got the multitasking.h library on the Arduino IDE

Sorry, but I have no experience of that library

What you seem to want to do looks perfectly possible without the overhead of a multitasking library as long as you write the program correctly.

Irvanmustofs55:
thanks for the advice,

I got the multitasking.h library on the Arduino IDE,
can he work like
task1 (do program 1)
task2 (do program 2)
all run in 1 program sketch?

I don't know the multitasking library.
All you need ot do is structure your program like this;

void loop()
{
    task1();
    task2();
}

However in your tasks you cannot use delay() and the time spent in each task must be short enough that it will allow the other task to run as quickly as it needs to.
To understand how you can stop using delay() read this tutorial

When you call delay() your sketch does nothing until the delay has elapsed, that is why you need to avoid it.