0

My project requires that a hinged box be opened approx 90 deg. with an servo controlled with an Arduino, staying open for approx. 90 seconds. When the lid is open, then a lift mechanism with a stepper motor, also controlled by the Arduino, will raise a platform for approx 60 seconds then lower the platform and close the lid. I an new to coding the Arduino but my research leads me to multitasking with millis().state machine, Can someone help with this


I want to "sandwich" the stepper action in between the servo action


Is changing the project to having the lid opening and the platform coming up (at an appropriate slower rate of course) together,and then reversing the action, then be multitasking? If so, can someone steer me to help with this scenario?


Thanks to all for their response's. I think that I am still to much of a "newbie 1.0" to understand (and modify) the solutions offered. I did find this post.... https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-clean-sweep....which seems to be enough of a explanation (with code) for me to begin to get a grip on a solution to my project. I'm sure that I will ask for help in the near future about certain aspects of this sketch. I welcome anyone's comments on O.O.P.

8
  • Maybe this will help? – Majenko Apr 8 '20 at 19:27
  • I don't see any multitasking requirement in your description, but in general you're right. Just write your sketch such that a single loop() run does not need any time, but only checks if there's anything to do now. The famous BlinkWithoutDelay example is not about blinking, but about a state variable. – DataFiddler Apr 8 '20 at 19:41
  • You can search for FSM (Finite State Machine). That is the general structure, that you will want to write your code in. Have you looked into the BlinkWithoutDelay example and understood it? That is crucial. There are many other tutorials about millis() on the web. What exactly was your problem with them? We need to know, what specific is your problem with writing the code, so that we can help you – chrisl Apr 8 '20 at 20:08
  • millis()-multitasking probably isn't the best option when controlling a stepper or a servo. Especially the latter usually require accurate timing. The better option is to use the atmega's hardware timer to generate the required signals – Sim Son Apr 8 '20 at 21:15
  • the description that you provided is similar to have breakfast, work for 4 hours, have lunch ... there is nothing multitasking about that ... it is just a sequence of actions – jsotola Apr 9 '20 at 2:37

Browse other questions tagged or ask your own question.