Arduino - How to Split a Program Into Different Files

Поделиться
HTML-код
  • Опубликовано: 5 окт 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 9 месяцев назад

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

  • @ET_AYY_LMAO
    @ET_AYY_LMAO Год назад +5

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

  • @vaishakhchavan8838
    @vaishakhchavan8838 Год назад +1

    Fantastic. Clear and perfect pitch. Appreciate the effort.

  • @lubenhristov1316
    @lubenhristov1316 5 месяцев назад

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

  • @baghiat_salehat
    @baghiat_salehat 2 года назад +1

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

  • @EngineeringToExcel
    @EngineeringToExcel 2 года назад

    Very good explanation.

  • @KHALIFLA
    @KHALIFLA 2 года назад

    Very Helpful, Thanks you

  • @Abdelrahman_Hosny
    @Abdelrahman_Hosny Год назад

    Very helpful
    Thank u

  • @mehmetaltinsoy525
    @mehmetaltinsoy525 3 месяца назад

    Thanks

  • @ELKopps11
    @ELKopps11 Год назад

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

    • @RoboticsBackEnd
      @RoboticsBackEnd  Год назад

      Great to see both the question and the answer :)

  • @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.

  • @AtomTiger3460
    @AtomTiger3460 2 года назад

    Thanks a lot!

  • @viktor_1939_
    @viktor_1939_ 18 дней назад

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

  • @carlosviana694
    @carlosviana694 Год назад

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

  • @prachethire812
    @prachethire812 2 месяца назад

    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.

  • @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.

  • @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

  • @ellisjacobs5011
    @ellisjacobs5011 2 года назад

    thank you.

  • @champion6929
    @champion6929 2 года назад

    thanks a lot

  • @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

  • @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.

  • @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

  • @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!! 👍

  • @behzadabf
    @behzadabf 2 года назад

    perfeeect..!!!!

  • @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...

  • @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);

  • @muigaisimon4103
    @muigaisimon4103 Год назад

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

  • @realtuners707
    @realtuners707 2 года назад

    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

  • @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