How to multi-task on an Arduino

Sdílet
Vložit
  • čas přidán 3. 08. 2024
  • I'm on vacation (so no hardware to show) but I wanted to put out a video showing how to do simple multi tasking on an Arduino. In this video I demonstrate how to make 2 LEDs at different speeds simultaneously. This video also shows how to use the Metro library for Arduino.
    Link to multi tasking sketch: github.com/ItKindaWorks/sketc...
    Link to Metro library: github.com/thomasfredericks/M...
    Subscribe for more weekly videos!
    Follow me on Twitter @itkindaworksinc
    My site with even more tutorials is itkindaworks.com!
  • Věda a technologie

Komentáře • 170

  • @caseyheath8131
    @caseyheath8131 Před 4 lety +16

    Buddy if I ever meet you I'm giving you a big hug! I'm working on a big project involving an Arduino and this is exactly what I needed to know!

  • @josecr6866
    @josecr6866 Před 7 lety +2

    Sir!!! It's a great Work!!! That's so helpful!!! One of the best and easy library for Arduino!!! Thank you very much for this colaboration.

  • @heatherpecho6094
    @heatherpecho6094 Před 5 lety +4

    Thank you so much for the video! I actually understand the code a gazillion times better now! Thank you again!

  • @yoyojoe5395
    @yoyojoe5395 Před 6 lety +3

    as a newbie to the Arduino this is brilliant, just what I was looking for, Thank You very much for this. I think I'll be able to adapt your example to switch multiple leds with varying different on and off intervals i.e. time ON interval different to time OFF interval (a self appointed challenge to get my head around and develop my knowledge and experience with this platform). I can now stand on the shoulders of a giant :), just love it.

  • @MaxiG
    @MaxiG Před 5 lety +2

    Great! its 2019 and this video change my way to see arduino programming, thanks!

  • @joshuathurman1847
    @joshuathurman1847 Před 6 lety

    This lack of skill here has stopped me in many previous projects. I know have a solid solution thanks to the hard work put into the library and tutorial video.

  • @princeofdenmark9142
    @princeofdenmark9142 Před 5 lety +3

    I was just using modulo of the run time. Thanks for the tip.

  • @0Arturo0
    @0Arturo0 Před 7 lety +1

    thanks a lot !!
    i was searching something like this !

  • @davidkempton2894
    @davidkempton2894 Před 8 lety +1

    Great little tutorial. Thanks.

  • @Julian-pg9dx
    @Julian-pg9dx Před 8 lety +1

    Keep going, I love your videos!

  • @elmoolsen9484
    @elmoolsen9484 Před 6 lety

    thanks for you video. i have a problem very VERY similar to what was explained and i will explore the Metro library real soon.

  • @gerhardbiebl9778
    @gerhardbiebl9778 Před 2 lety

    I have been working as a Software Developer for more than 40 Years, using each and every type of Computer, each and every Programming Language and Operating System available at its time and have been teaching lots of Students and Engineers at almost every great Company in most of Europe. Today, i am 67 Years old and retired. I have held many Courses on Multithreading, Multitasking and Parallel Computing and therefore i would like to make the following Topics clear, since there still is a lot of Confusion (i tried to keep it compact):
    Regarding "Parallelism":
    Your Computer may have as many Cores as you can imagine, real Paralellism only happens "between" these cores. As each Core has its own set of registers; working only with these, the core can do something while the other Cores do different things.
    Regarding "Hyper Threading cores":
    They can execute more then 1 Task at the "same time", BUT - they still have only one set of registers, so no "real" parallelism in this feature, but "simple" multithreading instead.
    By the way, Intel had temporarily stopped implementing Hyper Threading in its CPU's for some time.
    Conclusion:
    Even using many cores in parallel, parallelism is impossible in the very moment one of these cores does access memory or IO ports, since these resources only exist once in a Computer, so all other cores wanting to access memory or io have to wait - ciao Parallelism ! So it stays true - a Computer can only do one thing at a time, if it needs resources which are only available once. And it will need them for certain.
    Modern, fancy High-level Languages hide these Facts from you, so it is not uncommon that your Software "sometimes" is acting strange while mostly runs with no Problem at all.
    Problem is, Computers nowadays are so insanely fast that you cannot notice these bottlenecks, and debugging this is a real Chore, so you always should start Parallel development on one single Computer, best with only one Core to verify basic functionality, and then switch to Multiple Cores or Parallel Computers.
    The only way to do real parallelism is working with parallel computers - which means supercomputers or networking computers distributing Tasks to different Computers within the virtual or real System (see SETI Project, for example).

  • @1nvertedReality
    @1nvertedReality Před 4 lety

    Now I am only updating data to a Nextion display once per second. Got rid of 1000ms delay! Freed up serial coms for receiving hopefully.
    Thanks! Awesome video!

  • @Hersik
    @Hersik Před 5 lety +1

    Really helpful video, thank you!

  • @b.schneider7234
    @b.schneider7234 Před 5 lety

    Thank you. This is very helpful!

  • @mahendragavel3543
    @mahendragavel3543 Před 3 lety

    Thanks a trillions ! was looking just for this!!

  • @indeterminatedude7334
    @indeterminatedude7334 Před 3 lety

    exactly what i was looking for !

  • @chivainmanfoumbi9026
    @chivainmanfoumbi9026 Před 3 lety

    WOOoo !!! Maaannnn !! you just saved me a looooot!!!!! thanks DUDE !!! Stay blessed !!! everything is clear NOW !!!

  • @aaroncake
    @aaroncake Před 5 lety +1

    You don't need any external libraries to do this. Just keep track of millis() and compare it to the last time the loop ran. The IDE even comes with an example called "Blink Without Delay" which demonstrates this.

    • @ItKindaWorks
      @ItKindaWorks  Před 5 lety +1

      Yes I know but for beginners I've found that metro is much easier to learn (I know from both experience myself as a beginner learning this so many years ago and from teaching it now to those who are new to arduino). Behind the scenes metro is doing exactly the same thing but it hides some of the complexities. Eventually it would be good to learn the manual way but for those who just want to get something working, metro is an easy to learn solution.

  • @Bruh-hx1ro
    @Bruh-hx1ro Před 3 lety +1

    thank you so much bro! this helped me out

  • @michaelmoorrees3585
    @michaelmoorrees3585 Před 7 lety +8

    I've done this kind of thing, for decades, on various microcontroller families (AVR, HC05, 8051 ...). I've always called it "poor man's multitasking", since it doesn't use a pre-canned RTOS package. The use of timer interrupts and state machine design, allows several subroutines to run concurrently. This is basically what an RTOS does, but you just create your own, simplistic version. Arduino has a timer interrupt library, to operate similarly:
    playground.arduino.cc/code/timer1
    I also design my code in block diagrams. These operate the same way as different circuit blocks in hardware. Info is passed between the various blocks as variables, from boolean (or as we old farts call "flags"), to whole arrays.

    • @rokljhui864
      @rokljhui864 Před 7 lety

      Cooperative Multi-tasking.

    • @warlordelos
      @warlordelos Před 5 lety

      How can you run both task's under pin 6 concurrently? If I don't want to use multiple pins.

  • @IHRNepal
    @IHRNepal Před 4 lety

    This is what i really want to know ...Thankyou sir..

  • @pascha4527
    @pascha4527 Před 2 lety

    I always implemented my own scheduler, I create task that have a "timer" and it will fire a callback function when the time is over. It can be started, stopped, paused and also it can be a recurring timer that will call the function multiples times at a set interval. Its lightweight.

  • @jegsawu6434
    @jegsawu6434 Před 3 lety

    This is very helpful, thanks

  • @dezzodarling
    @dezzodarling Před 6 lety +1

    Might not work for everyone, but for repetitive uses, setting up an "object" makes it really easy to clone - just change the values of the established variables.

  • @SimonYells
    @SimonYells Před 6 lety +3

    Thank you ! :)

  • @clichereful
    @clichereful Před 7 lety

    This is one of the most helpful videos I've seen on youtube. Thank you so much for sharing this!

  • @dilshan4028
    @dilshan4028 Před 4 lety

    Thank you.That is excellent....

  • @bombproof831
    @bombproof831 Před 5 lety

    You could also eliminate the overhead introduced by using compare functions and implement interrupts to pass control to the other task and also manipulating registers directly using bitwise logic.

  • @dylanmissuwe4839
    @dylanmissuwe4839 Před 8 lety +5

    you can also do this:
    if (millis/1000 % 2 = 0){
    digitalWrite(13,HIGH);
    }else{
    digitalWrite(13,LOW);
    }

    • @ItKindaWorks
      @ItKindaWorks  Před 8 lety +4

      Yes that would work for this example however my purpose with this video was to show a dead simple way to do general multi tasking. Plus that method also has a lot of redundancy as at any given moment it will either be spamming the LED on or off over and over rather than just turn it on once or turn it off once. I feel like % and millis are also not exactly beginner concepts. I was even somewhat uncomfortable introducing ! in this video as it is geared towards beginners which is why I tried to explain it out a bit. The great thing about the Metro library is that it abstracts those concepts away from the programmer so that they can focus on doing the actual task. This was also more about general methodology than specifics.

    • @mainhattencalling
      @mainhattencalling Před 5 lety +1

      Why "millis/1000 % 2 = 0" instead of "millis % 1000 = 0" ?? What would be the difference?

  • @ninek8
    @ninek8 Před 4 lety

    Idk why but tries to blink 2 lights at once at different speeds without the library and that works pretty easily. The code was about the same size as the one you wrote while using the library. But obviously it will be harder for larger projects and that's where the library comes in. Thanks for the help

    • @ItKindaWorks
      @ItKindaWorks  Před 4 lety

      there are many ways to skin a cat. also programming....

  • @runforitman
    @runforitman Před 5 lety +1

    I would’ve thought you’d be given something like
    Loop
    {
    LED1 High
    LED2 High
    Delay 500
    LED2 Low
    Delay 500
    LED1 Low
    LED2 High
    Delay 500
    LED2 Low
    }
    Since that’s what I’d try to do if I didn’t know about any sort of multithreading

  • @LearnFromCharlie
    @LearnFromCharlie Před 8 lety +2

    Hope your having a great time on your vacation :) .... great work on the DC motors ...you sir are a genius ...can u make a video when you get back from your holidays on how to control AC motors eg. fan speed control using arduino ,i have been looking around but could not find anything as great as your tutorials with DC motors..plss help me out .. tc enjoi

    • @ItKindaWorks
      @ItKindaWorks  Před 8 lety

      +aakash salvi hey thanks! Vacation has been great! Hmm I'll have to look into it, ac motors and ac circuitry in general is a bit outside my knowledge set but I've been meaning to learn more about it. I specifically want to make arduino based AC dimmer circuits for lights but I imagine more or less the same idea would apply for ac motors as well.

    • @LearnFromCharlie
      @LearnFromCharlie Před 8 lety

      I saw sumthing with triacs .. But i could not get how to provide inputs ...m sure u will get it in a glance

    • @ItKindaWorks
      @ItKindaWorks  Před 8 lety

      +aakash salvi yeah triacs are definitely the way to go but last time I looked at least light dimmers I think there might be a feedback circuit that is needed to detect the point in ac sine wave so that you can trigger the triac correctly. Could be wrong about that but I feel like that's why I stopped last time I started looking in to that

    • @LearnFromCharlie
      @LearnFromCharlie Před 8 lety

      +ItKindaWorks i have absolutely no idea i have learnt evrything from your videos only so please mke a tutorial on this too....

    • @ItKindaWorks
      @ItKindaWorks  Před 8 lety

      +aakash salvi haha well I will definitely try to get it figured out! Just gotta learn it myself first :)
      And thanks for being a loyal viewer, it's people like you that keep me going!

  • @wells5150
    @wells5150 Před 3 lety

    This was a great intro. Can you update with chrono and why & when to use instead of millis? TY

  • @lordorion8657
    @lordorion8657 Před 5 lety +1

    Believe it or not, the Apollo computers on the Lunar Lander also does this method, which is to do multiple commands really quickly. Apparently, if you put too many commands however, it will overload and give you an alarm, which happened on Apollo 11 with 1201 and 1202 alarms.

  • @photogyulai
    @photogyulai Před 4 lety

    must have video for Arduino

  • @perkunast9680
    @perkunast9680 Před 7 lety

    I spent almost a year with this problem, I wanted to multitask so many things. Millis got way to complicated to code, RTOS is impossible to try to figure out. I dumped the Arduino and went C# had the program up and running in no time. Never knew metro even existed. Thanks

  • @krallopian
    @krallopian Před 7 lety +2

    Just getting in to C++ and Arduino but from what little I've seen, I would have just written, "digitalWrite(blinkPin1, HIGH); delay(500); digitalWrite(blinkPin2, HIGH); delay(500); digitalWrite(blinkPin1, LOW); digitalWrite(blinkPin2, LOW); and to me that would blink both at the same time. However after seeing time and time again today in videos that DELAY pauses the Arduino, I've been looking at using millis() and it seems this Metro library is some sort of short cut to typing out individual millis() code? Either way, happy I found this video, thanks!

    • @ItKindaWorks
      @ItKindaWorks  Před 7 lety +3

      Yeah, the metro library basically abstracts the millis code away from you so that you can focus on just writing the code that you want rather than getting caught up with the timing of things. It's a hard thing to get used to at first that the Arduino (and really any computer for that mater excluding things like multiple cores) can only do one thing at a time.

    • @krallopian
      @krallopian Před 7 lety

      Yeah coming from ActionScript from years ago saying, "do this, and this, and this... and this and this AND THIS AND THAT AND THIS" while mouse over or something, heh sort of just "experienced" that the computer does multiple things at once, even though it doesn't at all. *cheers =)

    • @PeterAbt
      @PeterAbt Před 7 lety

      James Heslop your code is missing some stuff 🤔
      - one more blink cycle for the 2nd led... ✌

  • @gogialexidze9587
    @gogialexidze9587 Před 4 lety

    Thank you !!!! Great!

  • @gerhardbiebl9778
    @gerhardbiebl9778 Před 7 lety +6

    In order to switch the state of a boolean variable from true to false vice versa, the simplest way is a logical XOr operation:
    bool variable = false;
    Variable ^= true;

    • @mefugoenmicarro
      @mefugoenmicarro Před 5 lety

      Yes, but you are missing the point of this video here.

    • @pascha4527
      @pascha4527 Před 2 lety

      I find that
      variable = !variable;
      is more a visual represention of what is going on.

    • @gerhardbiebl9778
      @gerhardbiebl9778 Před 2 lety

      @@pascha4527 Well, do as you like. An XOR Operation is the logical inversion of the binary value in that variable. But as (almost) always, there usually are more than one ways to do something. But i think that the XOR Operation is simply leaner and faster in machine code than any other way, since it can be transferred into machine code 1:1 whilst your code particle is actually made of 2 independant operations: an Inversion (the result of which has to be stored in a register) and an assignment operation (which transfers the value from the register to a variable) which together produce more machine code. The XOR variation can be realized with one single machine code operation on almost every processor

  • @kwesimanueghan3785
    @kwesimanueghan3785 Před rokem

    Thanks, it works.
    But will there still be an overflow for the millis() function?
    I really need this for a project

  • @unglaubichuberlieber8048

    thanks !!! no BUTs and NO suggestions, and only this : THANKS !!! THANKS !!! THANKS !!!

  • @PileofKyle
    @PileofKyle Před 4 lety

    Awesome!

  • @andrewwatts1997
    @andrewwatts1997 Před 2 lety

    I love this idea. Can the metro library also generate interrupts ? I would like to run a timed instance and have an interrupt trigger the execution of a function, instead of constantly checking in loop if the time has passed.

  • @donprefontaine3237
    @donprefontaine3237 Před 3 lety +1

    Add this video link to the start of your RTOS series, please.

  • @mihailucian409
    @mihailucian409 Před 3 lety

    until now to run several processes in parallel i used 2 arduinos using I2C Bus but it involved larger costs. you cut my production costs.Thank you

  • @momq1434
    @momq1434 Před 4 lety +1

    How about RTOS? The Metro program is polling .. Thank you for your sharing.

  • @robinwkhwkh
    @robinwkhwkh Před 7 lety +1

    Magic

  • @shrikantnikam2426
    @shrikantnikam2426 Před 4 lety

    Is it possible to make millis function in separate tab and use millis single line command like delay? For make code more simpler

  • @PerchEagle
    @PerchEagle Před 5 lety +1

    how about the method that do the following:
    unsigned long var_start;
    unsigned long var_cuttent;
    unsigned long var_period = 1000;
    if (var_current - var_start >= var_period ){
    ......
    }

  • @kaden56
    @kaden56 Před 6 lety

    What if I don’t want two things to continue happening again and again but rather just one time but I do want them to happen simultaneously. For instance what if I want to digital write high on one motor for 5 seconds and a second motor for 3 seconds simultaneously both starting at the same time? Would I need to use something to do with Millie instead?

  • @DiyintheGhetto
    @DiyintheGhetto Před 6 lety

    Hello Awesome video. But i have a small problem mine doesn't contain led blinks. I have a Ethernet shield with a Temperature sensor and a Oled screen that display the same temperature sensor as it does on the webpage. Problem. Is it updates the webpage every 5 seconds then updates the Oled screen every one second. with the current information. Problem is the the information that is on the webpage is different then what is on the oled. Can this method be adapted to something i have?

  • @shreyanshmalviya4968
    @shreyanshmalviya4968 Před 3 lety

    Please make a video on chrono library too....

  • @zeemixvideos6485
    @zeemixvideos6485 Před 5 lety

    sir i make an egg automatic incubator for my universty project i use two relays and one dht11 sensor
    (sorry for my english)
    one relay i use for gear motor to rotate egg turner
    and the seccond relay i use for a light and fan for controling temperature
    i use delay for rotating the eggs
    so the dht11 also use that delay and dont show the temperature between delay time please help me how can i use multi tasking
    i mean i want to see the temperature and humidity during delay time please replay

  • @imiebaka
    @imiebaka Před 6 lety

    It's really interesting at 9:20 How to make another method run outside the main while the main loop runs?

  • @arturmuellerromanov4438

    Good Man!

  • @Relentless_lel
    @Relentless_lel Před 6 lety +1

    from what i understand, that program fires blink2 at 500ms, blink1 at 1000ms and blink2 again at 1001ms. is that correct?
    so if i have a task (task1) that is more frequently called than the others(task2) duration, task2 is never done or if done delaying task1 ?
    or does this swap between the tasks to work at them almost parallel?

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety +1

      It swaps between the two tasks almost in parallel. It cant do them literally at the same time if their timers match up but the Arduino is certainly capable of turning a pin on/off faster than 1ms at a time. It may take on the order of microseconds but in most situations that is plenty fast enough

    • @Ben-amar
      @Ben-amar Před 6 lety

      Thanks for the precision! I was wondering too!

  • @VoeViking
    @VoeViking Před 2 lety

    Nice.

  • @abdulazeez1986
    @abdulazeez1986 Před 6 lety

    hi sir,
    can i do it with ultrasonic sensor and temperature sensor.
    if can please explain me

  • @BennyJacksonbj121
    @BennyJacksonbj121 Před 6 lety

    Well explained tutorial... May i know what IDE you are using .....

  • @RicardoPenders
    @RicardoPenders Před 4 lety

    It's a neat solution to the problem however why should I use the Metro library which I have to download and install before I can work with it when there's the already built-in timer called "millis " that I can use and basically do the same thing?

  • @pranavnarravula1267
    @pranavnarravula1267 Před 4 lety

    I want to run an ultrasonic sensor and LEDs, can I do that at the same time?

  • @warlordelos
    @warlordelos Před 5 lety

    How can you run both task's under pin 6 concurrently? If I don't want to use multiple pins.

  • @hidekiryuga3906
    @hidekiryuga3906 Před 7 lety

    Here the time is triggering it. But What if i want to do two or more functions at the same time which includes input and output. For example, Lets say i want a robot that moves hand when we move close to it and if we press the button it will move. but I want it to do both of these activities simultaneously like pressing the button and also move close to it. What should i do in this case

  • @sarveshmestry7501
    @sarveshmestry7501 Před 3 lety

    Sir can ardunio be coded in such a way that it performs task one after the another for example :motor1 starts and then stops, then motor2 starts and then stops

  • @LiviuPavel
    @LiviuPavel Před 6 lety

    @ItKindaWorks
    I thought the timer is resetting by itself, I'm only getting the timer TRUE after the interval elapsed since power on, after that, is always TRUE

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety

      How often are you calling the check method? It should automatically reset the timer each time the check method returns true. Does your setup or other code take a long time before it starts checking your timer? I think there are a couple of different modes with the Metro library, one that will run multiple times to "catch up" if the timer elapsed multiple times over (so if you had a 5 second metro timer and only checked it once every 15 seconds it would return true 3 times), and one that will just return once and skip missed checks.

  • @alenaugustine6416
    @alenaugustine6416 Před 5 lety

    Hello
    I am new to Arduino so please help me
    I want to run 3 loops same time
    1:blink led
    2: control relay on &off
    3:control another relay on &off
    It will be great if you help me

  • @HuyTran-zy9sv
    @HuyTran-zy9sv Před 3 lety

    I have not looked over the Metro lib yet but i think its use millis() logic

  • @Leilektsoglou
    @Leilektsoglou Před 3 lety

    Could we use this library for lighting up 2 leds pressing their pushing buttons simoultaneously ? (each push-button I wanna work as a toggle switch for each led separately, but I want if I press the 2 buttons at the same time to work as well)

    • @pascha4527
      @pascha4527 Před 2 lety

      Yes.
      int btnpin1=10;
      int btnpin2= 11;
      int ledpin1 = 12;
      int ledpin2 = 13;
      boolean ledstate1, ledstate2, btnstate1, btnstate2;
      void loop() {
      if(digitalRead(btnpin1) && !btnstate1) {
      btnstate1 = true;
      ledstate1 = !ledstate21;
      digitalWrite(ledpin1, ledstate1);
      } else {
      btnstate = false;
      }
      if(digitalRead(btnpin2) && !btnstate2) {
      btnstate2 = true;
      ledstate2 = !ledstate2;
      digitalWrite(ledpin2, ledstate2);
      } else {
      btnstate2 = false;
      }
      }

  • @vangeziyorum9725
    @vangeziyorum9725 Před 2 lety

    I made an ultrasonic height and weight measuring device. I wrote the codes with Arduino and arduino UNO. Normally everything works fine. But sometimes after waiting for an hour or two, I take a measurement, the device is measuring, it shows the numbers on the screen, but it does not print the result to the thermal printer. The numbers stay on the screen, then the device is reset with whatchdog. This is starting to get annoying. can you help me with this

  • @meer_kat5158
    @meer_kat5158 Před 3 lety

    Hi What is the difference between this approach and the ChibiOs apprach?

  • @darvinvarghese2536
    @darvinvarghese2536 Před 4 lety

    This uses millis....so it can be overflow...so is this program can overcome millis overflow?

  • @peterjohnnucom8176
    @peterjohnnucom8176 Před 6 lety

    Hi, can I set the Value of the metro as a variable for example
    Long interval = 1000;
    Metro wPumpMetro;
    wPumpmetro = Metro(interval);?

  • @salc9593
    @salc9593 Před 7 lety

    Can you use a PWM pin to fade an LED Up and Down while the other pin is Blinking LED?

    • @ItKindaWorks
      @ItKindaWorks  Před 7 lety +1

      You totally can!

    • @salc9593
      @salc9593 Před 7 lety

      Thank you... I am trying to run a For Loop Iteration (aka Larson eye ) sketch with another sketch which randomly light two LEDs using your Metro library. I would like to know if I need to incorporate a "While" statement so they can run separate from one another as they presently do. Please forget my question as I'm a Neophyte to Arduino programing... Thank you for your direction on this question.

    • @ItKindaWorks
      @ItKindaWorks  Před 7 lety

      When using Metro, it is preferable to not use while loops as they "block" other code from running. So if you had a loop to fade the LED up/down then the program would run that loop (fading the LED all the way up or down) and then it would blink the other LED. Instead of doing that you can use 2 metro timers (one for blinking and one for fading) and just make the fade timer something small like 5ms and have the fading LED just fade up/down a small amount each time the timer is triggered. Here is a small arduino script I had laying around already that does roughly what I think you want: gist.github.com/ItKindaWorks/512be9da4c6c6a2e61c99f48eaacb4f9

  • @WaWoChannel_Official
    @WaWoChannel_Official Před 6 lety

    sir, how to multitask on 8051? wether it's possible or not?

  • @goldenhawktechnology3009

    Cool

  • @bierhoch1011
    @bierhoch1011 Před 5 lety

    Is it possible to check a button during a led is blinking? Can anybody help me

  • @BigyanChap
    @BigyanChap Před 6 lety

    In a real-time embedded system program, while loop is also blocking code. Any substitute for blocking, obnoxious while loop?

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety

      This same mechanism can be used for looping. You just have to be a bit creative about how you implement your loop to prevent the code from blocking. One example would be to have a status variable that it set to true when "looping" and false when not. Then you could have an if statement that looks like
      if(shouldLoop == true && myTimer.check())
      //do some code that should loop
      // when some target condition is reached set shouldLoop to false
      Now you can have other code that surrounds this if statement and will execute even if the "loop" should be also running.

    • @BigyanChap
      @BigyanChap Před 6 lety

      +ItKindaWorks Nice. Worked well. :D

  • @14kukucka
    @14kukucka Před 6 lety

    How Did YOU put black background?

  • @tpespos
    @tpespos Před 3 lety

    Void Loop{
    LED1(High)
    LED2(High)
    Delay(500)
    LED2(Low)
    Delay(500)
    LED1(Low)
    LED2(High)
    Delay(500)
    LED2(Low)
    Delay(500)
    }
    Fixed
    Just kidding I learned a ton from this video

  • @scoot1632
    @scoot1632 Před 6 lety

    This is just what I have been looking for! Problem is, I have tried to add the Metro to my Arduino libary and the library error message says "Specified Folder/ZIP File Does Not Contain a Valid Library". Any ideas?

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety

      This usually happens when you unzip the library and your unzipping software creates a folder for the contents (so rather than looking like metro/ it looks like metro/metro/. Or it could possibly be that the folder isnt named properly. There cant be any dashes in the library folder name (Metro-master) for example. Just remove the "-master" part.

    • @lindawhitfield7582
      @lindawhitfield7582 Před 6 lety

      Hey, did you solve your problem? I go the same issue?

  • @ckrollish
    @ckrollish Před 7 lety +1

    I'm new to this and was wondering if you can run 2 servos and an led light strip off of 1 Arduino?

  • @lynettepuzon3328
    @lynettepuzon3328 Před 6 lety

    what particular kind of arduino would you need to run about 6 servos?

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety

      Based on the info on this page most Arduinos should be able to handle up to 12 servos so you should be able to use a standard one just fine.

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety

      www.arduino.cc/en/Reference/Servo

  • @aln9391
    @aln9391 Před 6 lety

    )))))))))))) It"s cool multitasking. Where are you from? Papua?

  • @jojo_glitching2970
    @jojo_glitching2970 Před 3 lety

    Is it just me or would it just be easier to have two void loops. Before you say anything I know you can only have one but why don't c++ allow two . I'm a tier higher than noob but I still don't know much about coding

  • @slookify
    @slookify Před 4 lety

    but how does the metro.h work? can we build it easy by ourself

  • @prestonsteimel1907
    @prestonsteimel1907 Před 7 lety +1

    It could be done in the loop only, with something like this:
    void loop() {
    digitalWrite(13, HIGH);
    digitalWrite(12,HIGH);
    delay(500);
    digitalWrite(12,LOW);
    delay(500);
    digitalWrite(13,LOW);
    digitalWrite(12, HIGH);
    delay(500);
    digitalWrite(12,LOW);
    delay(500);
    }
    Of course, once you can't easily find a common factor, it gets much more difficult, and we must resort to multitasking with the metro or TimerOne libraries.

    • @ItKindaWorks
      @ItKindaWorks  Před 7 lety

      Sure thats totally true that this example is not one that requires multi-tasking. Rather than come up with a complex example though, I figured it best to keep it simple to demonstrate how someone with a more complex problem could go about it.

    • @prestonsteimel1907
      @prestonsteimel1907 Před 7 lety +1

      Yeah I understand. :)

    • @prestonsteimel1907
      @prestonsteimel1907 Před 7 lety +1

      Great video, though!

  • @123killerization
    @123killerization Před 4 lety

    How complicated would this be without the Metro.h library?

  • @jamessutton9319
    @jamessutton9319 Před 3 lety

    Will this work on an ESP8266 as well?

  • @VArt1998
    @VArt1998 Před 3 lety

    wwhy me can;t add lirbrary. pls help

  • @justdoingodswork
    @justdoingodswork Před 3 lety

    We can do this using millis() function too

  • @arstudio5609
    @arstudio5609 Před 4 lety

    I can't observe the screen clearly as its blurr

  • @alexjakicic7695
    @alexjakicic7695 Před 6 lety

    When I tried this it said that metro didn’t name a type. What should I say it means?

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety

      It means that you'll need to download and install the metro library. There should be a link in the description of the video.

    • @alexjakicic7695
      @alexjakicic7695 Před 6 lety

      ItKindaWorks ok thanks

  • @TheRealQawser
    @TheRealQawser Před 5 lety

    Is it possible to do something like this with two piezos?

    • @ItKindaWorks
      @ItKindaWorks  Před 5 lety

      It depends, are you trying to use the piezo units as sensors or as speakers (or more specifically are you trying to play multiple sounds at the same time through 2 piezo speakers)?

    • @TheRealQawser
      @TheRealQawser Před 5 lety

      The idea was to make piezo stereo speakers.

    • @ItKindaWorks
      @ItKindaWorks  Před 5 lety

      Then probably not (at least with the piezo speaker library that I know about). While this could let you operate two devices at nearly the same time, the piezo speaker library only supports a single speaker device at a time. So even if you did write it in such a way that it tried to control both nearly simultaneously, it would only play sound from one at a time.

  • @moumilelion1
    @moumilelion1 Před 6 lety +1

    What is your IDE?

    • @ItKindaWorks
      @ItKindaWorks  Před 6 lety

      Sublime Text. It's not a great IDE but it is certainly my go-to text editor!

  • @krishnamakhecha902
    @krishnamakhecha902 Před 6 lety

    dear sir can you help me by building code for towering tiles by bigtime apk it is similar to stack game which is used to play game on smartphone via stylus pls.

  • @jaikishan0218
    @jaikishan0218 Před 5 lety

    Do this library support microseconds

    • @ItKindaWorks
      @ItKindaWorks  Před 5 lety

      It does not. It wouldnt be difficult to modify this library though to allow for microsecond timing by using the micros function instead of the millis function.

  • @zx10rheinzi
    @zx10rheinzi Před 5 lety

    Metro-Library does not work :( " Arduino says: it is not a valid Library ".....................any idea ?

    • @IHRNepal
      @IHRNepal Před 4 lety

      Now i am having the same problem.Did u solve ?

  • @zaid9166
    @zaid9166 Před 4 lety

    what about thread

  • @physicsandtechnology8794

    library not able to install