Skip to main content
edited body
Source Link
Duncan C
  • 5.8k
  • 3
  • 19
  • 31

As long as you're not using delay() or other blocking code, as John mentions in his answer, that approach will work fine. I have a fairly large project where I defined a class ArduinoObject. The ArduinoObject class has a setup method and a loop method, and the main sketch creates and manages an array of ArduinoObjects (and another stack of a subclass of ArduinoObject called a MenuObject that manages menus on the LCD screen the project uses.)

At times there are a dozen or more ArduinoObjects being called on each pass through the sketch's loop() function and it works just fine. The key thing is to write your sub-loops to be FAST. They should do a tiny amount of work on each pass, and then a little more on the next pass (if needed.) You never want one of your sub-loops to take enough time to make the other sub-loops "stutter".

As long as you're not using delay() or other blocking code, as John mentions in his answer, that approach will work fine. I have a fairly large project where I defined a class ArduinoObject. The ArduinoObject class has a setup method and a loop method, and the main sketch creates and manages an array of ArduinoObjects (and another stack of a subclass of ArduinoObject called a MenuObject that manages menus on the LCD screen the project uses.

At times there are a dozen or more ArduinoObjects being called on each pass through the sketch's loop() function and it works just fine.

As long as you're not using delay() or other blocking code, as John mentions in his answer, that approach will work fine. I have a fairly large project where I defined a class ArduinoObject. The ArduinoObject class has a setup method and a loop method, and the main sketch creates and manages an array of ArduinoObjects (and another stack of a subclass of ArduinoObject called a MenuObject that manages menus on the LCD screen the project uses.)

At times there are a dozen or more ArduinoObjects being called on each pass through the sketch's loop() function and it works just fine. The key thing is to write your sub-loops to be FAST. They should do a tiny amount of work on each pass, and then a little more on the next pass (if needed.) You never want one of your sub-loops to take enough time to make the other sub-loops "stutter".

Source Link
Duncan C
  • 5.8k
  • 3
  • 19
  • 31

As long as you're not using delay() or other blocking code, as John mentions in his answer, that approach will work fine. I have a fairly large project where I defined a class ArduinoObject. The ArduinoObject class has a setup method and a loop method, and the main sketch creates and manages an array of ArduinoObjects (and another stack of a subclass of ArduinoObject called a MenuObject that manages menus on the LCD screen the project uses.

At times there are a dozen or more ArduinoObjects being called on each pass through the sketch's loop() function and it works just fine.