Connect with us

Multitasking with Arduino

Discussion in 'Microcontrollers, Programming and IoT' started by etka besim, Jul 4, 2017.

Scroll to continue with content
  1. etka besim

    etka besim

    Mar 28, 2017
    i wanna control Speaker and Servo motor together with arduino . How can i control these together ? i hope you help me :)
  2. kellys_eye


    Jun 25, 2010
    The Arduino has multiple 'ports' that can be used to drive many different accessories simultaneously.

    Check out any reputable Arduino seller and look for speaker and servo modules that can be purchased to connect to the Arduino.

    It's then a case of either writing your own software or downloading one of the many 'sketches' that can be incorporated into your design.
  3. Mike_Lemon123


    Jul 7, 2017
    I don't know if it's the standard way but this is a way I developed multitasking.

    never use the function delay(); and if you need timing function for accelerations and stuff like that just use timers (I Use "long" variable for that) along with the function millis() and if statements to check if at the current interval you have reached that time. also I use some flags for some processes and store them in variables.

    Just say if you wanna learn about it more in depth but arduino has a good example about basic multi tasking using the example "delay without blink" of course it's not as accurate as using the delay function but it is essential sometimes and this processor is so fast you can't tell the difference.
  4. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    Jan 21, 2010
    If you implement your functions using state machines and no delays, you can call one state machines and then the next (alternating) and you will have a useful form of multitasking.

    Also be aware that the atmega chip has peripherals which can be set running and left (the PWM outputs are a good example)
  5. Mike_Lemon123


    Jul 7, 2017
    yeah but this PWM is static while running other commands.
  6. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    Jan 21, 2010
    Are you bit banging your pwm?
  7. sumeryamaner


    May 29, 2017
    If you want to get help, you must provide details. What do you want to output to the speaker? A simple square wave sound or an mp3 file? What kind of servo motor are you talking about? A regular R/C servo or something else? What have you done until now and at which point do you have problems?
    And finally, do you read the replies to your post?
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day