How to Combine Two Arduino Sketches

Поділитися
Вставка
  • Опубліковано 1 лис 2024

КОМЕНТАРІ • 33

  • @WhatMakeArt
    @WhatMakeArt  Рік тому +4

    Post any question about combining Arduino sketches in the comments

  • @drift9285
    @drift9285 5 місяців тому +1

    You have no idea how much this helped on my school project, thank you

    • @WhatMakeArt
      @WhatMakeArt  5 місяців тому

      I'm so glad! Hope the project turned out well

  • @teo7681
    @teo7681 Рік тому +2

    I have been working on an arduino project with zero c++ knowledge (only c) and this video helped sooooo mutch thank you!!!!

    • @WhatMakeArt
      @WhatMakeArt  Рік тому +1

      Glad it helped, hope your Arduino project turns out well 👍

  • @Anhidema
    @Anhidema 4 дні тому +1

    The most useful however technique !!!

  • @salc9593
    @salc9593 Рік тому +1

    Hi, Thank you for posting this very informative video as I had tried to copy on sketch to another, it took quite someone time to get the new combined sketch to work. This video and the Three Step as to How to copy and paste will make life a whole lot simpler. Thanks for help this neophyte to Arduino coding. 🙂

  • @arghyadas5789
    @arghyadas5789 10 місяців тому +1

    thank you for this amazing video sir, was really helpful.

  • @janvermond8032
    @janvermond8032 8 місяців тому +1

    I am trying to make an arduino sketch in which a number( +/- 8) of servo motors , one by one, take turns making a 180-degree sweep while during the sweep an LED corresponding to that servo motor lights up. A sweep code for 1 servo is no problem, multiple servo does not work for me. Are there any simple examples where servos take action one by one? Potentiometer "Switch State Machine Control Servos"" from Tinkercad is too much of a good thing. I am not a very experienced Arduino user.

    • @WhatMakeArt
      @WhatMakeArt  8 місяців тому

      Simple 6 Servos without delay www.tinkercad.com/things/jG6RVDEkuuc-6-servo-motors-without-delay
      Servo control with potentiometer example wokwi.com/projects/362259196144807937
      Multiple servo motors with potentiometers example www.tinkercad.com/things/coY9tQLYizF-potentiometer-switch-state-machine-control-servos

  • @galagatron5319
    @galagatron5319 Рік тому +1

    Hi, I have 3 different sketches I need run at the same time. 1 sketch uses multiple servos, second is multiple leds, third is the play of a recorded track. Do I use 3 sketches for 1 arduino or do I use 3 arduinos and sketch individually. If the latter, i don't know how to connect 3 arduinos and make that happen. I'm trying to make a animintronic project and need all 3 sketches to start with a push of a button. Please help with short answers. Thank you.

    • @WhatMakeArt
      @WhatMakeArt  Рік тому +1

      It really depends on what you want to do. You should be able to do that all with one Arduino. The first thing to do is copy all the parts before setup and make sure none of the variables have the same name. Then also make sure none of the pins are the same. Then inside the setup function do the same thing. Make sure you assign all the pins and variable values and you don't have repeats of pin assignments. Make sure you don't have repeat serial monitor starts.
      Then the harder part is combining the sketches and removing delays. If you use a millis timer and a state machine then you can work out each one.
      First step is just to make sure each of the elements work individually on a single Arduino. Then start combining them slowly.

    • @galagatron5319
      @galagatron5319 Рік тому +1

      @@WhatMakeArt thank you for your help. I'm not as much as a pro like you. Most of what you said is hard to understand but I'll research it. You said I have to remove delays but delays are very important in my project. What I'm wanting to make is a 5 to 10 min show using 3 figurines operated by servos. 2 servos for each figurine. 1 for arms and 1 for legs. Each figurine will be programmed to move or not move in conjuction with a prerecorded sound . The prerecorded sound will have spoken word that is for each character. So I need movement "timed" with the prerecorded characters voice. So programmed servos that coincide with the timing of the recorded track. I also want programmed leds to spot light each character when they speak.
      I'm new at this and I know I'm jumping into the fire here but I been trying to find the easiest way to do this. I have a few 16 channel servo/led drivers, a few nano's, a mega 2560, and a bunch of other stuff.
      I really appreciate your help, do you still think I should try to make this happen on one arduino?

    • @WhatMakeArt
      @WhatMakeArt  Рік тому +1

      Here is a link to a state machine example whatmakeart.com/courses/experiments-in-electronic-arts/2023-spring/06-arduino-multitasking/6-02-arduino-state-machine that uses timers, also on this site are examples of removing delays and millis timers
      Give it a shot and if you are still stuck, post a link to your code on the Arduino Forums,forum.arduino.cc/ and post a link to it here, and I'll take a look

    • @galagatron5319
      @galagatron5319 Рік тому

      @@WhatMakeArt thank you sooo much sir!!!

  • @yoiiii5962
    @yoiiii5962 Рік тому +1

    hi, does this work with codes that have very different functions? such as my other sketch is to run a camera that scans for qr codes and the other sketch is for sending a message through sms when that qr code is scanned? do you have an idea on how i could connect those two functions?

    • @WhatMakeArt
      @WhatMakeArt  Рік тому +1

      The same process, copy all the stuff before setup, copy all the stuff in setup, copy all the stuff in the loop, copy all this stuff after the loop
      The function that runs the camera either stores the QR code in a variable or a file or returns the QR code.
      The function that sends the SMS, must have a trigger that causes it to run. If it doesn't then you can make a simple conditional statement that when a QR code is updated then run that function.
      You may need to create a function that makes these two interact. Just make sure none of the variable names overlap. The other thing is to make sure that they're not blocking delays in the code.
      Also, the Arduino forms are a good place to get specific project help because you can paste example code

  • @Stagmike
    @Stagmike Рік тому +1

    Have I have a code that takes numbers , from lightsensors and pontetiometers , and the other code is from yt, that you connect a pin to a0 that's going to a slider pontetiometer and you connect LEDs to Digitals, and when you get the pont. High the LEDs going on like an audio console, I want to combine the codes but I have problem...

    • @WhatMakeArt
      @WhatMakeArt  Рік тому

      What is the specific problem?
      Make sure that you don't have any Arduino pins that are repeated. Then make sure no variable names repeat.
      Good idea to make things into functions and then use millis timers and then eventually a state machine.

    • @Stagmike
      @Stagmike Рік тому +1

      @@WhatMakeArt it's ok yesterday I completed the code , I made it that to take the sensors values to pure data on pc, and I have 1 slider pontetiometer that works with LEDs, and 2 other pontts.
      The 2 are working fine, but the slider pont. It goes crazy!!! It's like to have a hand that play with the pont every msec

    • @WhatMakeArt
      @WhatMakeArt  Рік тому

      Sweet, sounds cool

    • @Stagmike
      @Stagmike Рік тому +1

      @@WhatMakeArt cool but my brains isss dgsjsjkskd haha

  • @nujabes__
    @nujabes__ 11 місяців тому +1

    I've combined 2 sketches for 2 sensor, Ldr sensor module and sound sensor but only the LDR works

    • @WhatMakeArt
      @WhatMakeArt  11 місяців тому

      Double check that there are not blocking delay(); calls or other shared resources that block the sound, double check that all code is present and all functions called

    • @nujabes__
      @nujabes__ 11 місяців тому

      @@WhatMakeArt is there a way I can show you the sketch? I have 0 knowledge on this and Just started to know it yesterday

  • @Panchothefatcat
    @Panchothefatcat Рік тому +1

    How do you put myservo attach? It only works for one servo is it myservo.attach(10/9) or myservo.attach(9,10) because i cant figure out how to code two servos i programed the code already but i can’t duplicate it for 2 servos any help?

    • @WhatMakeArt
      @WhatMakeArt  Рік тому

      To control more than one servo motor with an Arduino, you need multiple servo objects with different names such as myservo1 and myservo2
      Create each servo by name and then control each by the named object
      Here is a link to six servos with an Arduino:
      www.tinkercad.com/things/coY9tQLYizF
      Here is a link to 2 servos with a potentiometer controlling the behavior
      wokwi.com/projects/362259196144807937

    • @Panchothefatcat
      @Panchothefatcat Рік тому +1

      @@WhatMakeArt thanks i figured it out

    • @Panchothefatcat
      @Panchothefatcat Рік тому +1

      @@WhatMakeArt but how would you power a servo for a cosplay?

    • @WhatMakeArt
      @WhatMakeArt  Рік тому +1

      You can use a battery to power the servo. Wire directly from the battery, the positive wires and then use the negatives all tied together with ground.
      Don't try to power the servos from the Arduino pins, give the servo power from the battery and then just use the signal wire to the Arduino pins