Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

How to make Arduino run multiple tasks

Microcontroller on Arduino is usually Atmega328p which has very limited resources like 32K of Flash and 2K of RAM. Trying to run RTOS or any other real time operating system doesn’t make sense. It is possible, but not forth and it is not effective. But if you sill want to run multiple tasks on Arduino there is a way out. Adafruit walks us through simple tricks how to implement your own real time scheduler.

microcontrollers_Animate

The idea they are talking about is not RTOS, but state machine. All you have to do is to keep an eye on Arduino internal clock which counts miliseconds (returned by millis() function) from program start. Each separate task is considered to be separate state machine which keeps track of time. Once its time comes – it executes task and goes low until its time comes again. This way there is no problem to run many tasks like blinking LEDs at different rate or turning servo motors at different rates and angles. Once you get used to it, you can go further and create object oriented program which looks more elegant and easy to expand. So next time if you program grows big and clumsy, remember about multitasking.

[..Source link..]

Bookmark the permalink.

Comments are closed.