I am working on a project where I have to drive a stepper motor and BLDC motor with only one Arduino(Portenta Machine Contrl) at the same time. I am quite stuck on how to do this.
If anyone has some idea or suggestion, please do let me know.
The first thing that you will need to do is to get rid of the calls to delay() as when used to control one device it will prevent control of the other one and vice versa. Instead you need to implement non blocking timing, probably by using millis() for timing. are you familiar with that concept ?
Most, probably all for loops will have to go to and you will use the loop() function to do the looping for you in conjunction with millis() non blocking timing
A useful way to do this would be a state machine for each device so that you can control the section of code that is running for each device and its timing. Are you familiar with such a way of writing a program, probably by using switch/case to change between program states at the appropriate times
In summary, you have a lot of work on your hands to combine control of both devices and the 2 sketches cannot be simply merged for the reasons given above