Arduino - How to Split a Program Into Different Files

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

КОМЕНТАРІ • 47

  • @andrebalsa203
    @andrebalsa203 2 роки тому +11

    Excellent! Very clear explanations, thank you very much. I am immediately going to use this knowledge for my current project (which has reached 2000 lines of code).

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

    Great video, I think this video will help a lot of people who don't know how the scheme of c and c++ works, was very clear and concise!

  • @raymondmichael4987
    @raymondmichael4987 10 місяців тому

    Finally, someone I can clearly understand the use of cpp and h files 😊
    Thanks buddy

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

    Fantastic. Clear and perfect pitch. Appreciate the effort.

  • @lubenhristov1316
    @lubenhristov1316 6 місяців тому

    Very useful video, showing in details the proper sequence of building structured Arduino project! Well done!

  • @ET_AYY_LMAO
    @ET_AYY_LMAO Рік тому +5

    What 99% of people coming here wants to know is, use double quotes, not < > when including files.

  • @baghiat_salehat
    @baghiat_salehat 2 роки тому +1

    Thank you. It was the best way to understand the header file.

  • @prachethire812
    @prachethire812 3 місяці тому

    Doesn't works, I am using adafruit neopixel library, It always gives error "object not defined". I mean the created neopixel object. I tried defining the object in header file then too there is error.

  • @mehmetaltinsoy525
    @mehmetaltinsoy525 4 місяці тому

    Thanks

  • @rahul6306
    @rahul6306 2 роки тому +2

    Hi, I have a few doubts.
    1. f I am using the suppose 'X' library in Arduino which is used for let's assume filtering noise from the received signal.
    2. so does that mean, that the library should consist of a .cpp and .h file?
    3. .h file is like for declaring the variable?
    4 .cpp is where the actual method(function) is created for filtering the noise?
    5. and in the .ino file which acts as a receiver(created by me), from that I need to call the function which I want to use from my X library?
    thanks in advance.

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

    Três bien... Beaucoup m'aide...

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

    Very helpful
    Thank u

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

    Now convert this into an LED class. Plans to do that? Or is there a video on that? I found it. Thanks!

  • @EngineeringToExcel
    @EngineeringToExcel 2 роки тому

    Very good explanation.

  • @AtomTiger3460
    @AtomTiger3460 2 роки тому

    Thanks a lot!

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

    So much thanks

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

    5.28 shouldn't you be including cpp file here? I mean where is led_functions.cpp even mentioned once?

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

      In your code you only include the .hpp file.
      Then how the .cpp file is used, that's the magic of compilation :)
      If you want to understand more, make some research on how C++ programs are compiled

  • @KHALIFLA
    @KHALIFLA 2 роки тому

    Very Helpful, Thanks you

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

    I had some code that was working fine. I then split it into the .cpp file, with the corresponding .h file.
    The issue I have is that now when I call the SPI functions in the new .cpp file I get errors about "unknow class type", errors in the actual SPI library that is part of the arduino ESP32 library.
    Any ideas why this is the case, or is it possible that the SPI library for the ESP32 is not able to be used this way?
    Any advice would be greately appreciated as I have spend hours on this and not got any further.

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

      I would say to make sure you use the #include tags in every file where you need the library

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

    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.

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

    Lorsqu'on utilise ce genre de façon de faire (header) et que l'on appelle des fonctions dans ce header en passant des variables, pas de problèmes ? Les variables globales sont présentes aussi ? Merci

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

      Pas de problème, une variable qu'on passe dans une fonction se retrouve en "variable locale" dans la fonction, que la fonction soit dans le même fichier ou pas. Pour les variables globales oui elles sont aussi présentes.

  • @viktor_1939_
    @viktor_1939_ Місяць тому

    do not use byte or similar thing? your code become unexportable to other platform.

  • @ellisjacobs5011
    @ellisjacobs5011 2 роки тому

    thank you.

  • @MayankMehraMusic
    @MayankMehraMusic 2 роки тому

    I have a question. Why use .cpp, .h extensions ? Arduinos default .ino files directly imports functions. So we just call functions direcrly. Im just curious

    • @RoboticsBackEnd
      @RoboticsBackEnd  2 роки тому

      This is a way to better organize your own code. Imagine that you have 2000 lines in your main .ino file, this is going to be horrible to manage :)

    • @MayankMehraMusic
      @MayankMehraMusic 2 роки тому +1

      @@RoboticsBackEnd Okay. How about managing the code on multiple ino files. I'm just trying to understand the difference. Really appreciate your response.

    • @RoboticsBackEnd
      @RoboticsBackEnd  2 роки тому

      @@MayankMehraMusic well technically I think you could create multiple ino files (make sure you don't have multiple setup() and loop() functions though). But I've never done it, never seen it, and I think it doesn't really make sense --> .h and .cpp files are working well and that's what you'd do in any other cpp project

    • @MayankMehraMusic
      @MayankMehraMusic 2 роки тому +1

      @@RoboticsBackEnd Okay. Understood. Thanks alot for your valuable time.

    • @RobiBue
      @RobiBue 2 роки тому

      @@MayankMehraMusic Sorry, I hate to be pedantic here, and I do understand the reasoning for the .h and .cpp files, but I fail to understand the reason of creating multiple prototypes for a single function like:
      void powerLED(byte pin, bool state);
      and then in the loop just write:
      powerLED(LED_PIN, HIGH);
      and
      powerLED(LED_PIN, LOW);

  • @champion6929
    @champion6929 2 роки тому

    thanks a lot

  • @behzadabf
    @behzadabf 2 роки тому

    perfeeect..!!!!

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

    how can i like the video twice?................hide your brain before they bewitch you sir😁😁😁lol

  • @MonkeyMan9999
    @MonkeyMan9999 2 роки тому

    Works good. One problem though. Was unable to use Serial.print from the .cpp file. This was true even after issuing Serial.begin(9600). Correct baud options and termination options were selected in terminal window. Still no output...

  • @thevein8583
    @thevein8583 3 роки тому +1

    Nice tutorial!!
    I got one question.. if i want upload all that split file... Can i upload one by one? Or it has another method to upload it?.. i got a split file in internet but i dont know how to upload that. Hope u can help me sir..
    Done subscribe sir!! 👍

  • @realtuners707
    @realtuners707 3 роки тому

    followed this exactly with a simple program of my own, and it fails repeatedly. I'm literally doing the exact same things, but it compiles just fine if I leave it all in one tab.
    Been trying to learn how to do this for months now.

    • @jugbang9387
      @jugbang9387 2 роки тому

      Hi, I got the same pb and solved it by naming the tab led_functions.c and NOT .cpp and by replacing #include "led_functions.h" in the ino tab by #include led_functions.c. Hope that will help

  • @yadwindersingh9494
    @yadwindersingh9494 3 роки тому +2

    What is the benefit of this

    • @elko9404
      @elko9404 2 роки тому

      When your projects get larger, this makes the main program file more readable

  • @skoire7305
    @skoire7305 2 роки тому

    Do you have to use .cpp , can it be .c ?

    • @RoboticsBackEnd
      @RoboticsBackEnd  2 роки тому

      .c extension is for C language only, here as you use C++ (well, a subset of C++), you need the .cpp extension

  • @yjc5805
    @yjc5805 3 роки тому

    thanks very much