1. Uncle peanut butter

    Uncle peanut butter TrainBoard Member

    26
    19
    2
    Need an opinion from the folks on here that have programming skills. I have my DCC++ set up and running and am ready to experiment with the capabilities of the world or arduino as it applies to our hobby.
    I have zero programming experience but I feel if I can learn to speak the language necessary it will make my projects more rewarding.
    I’m looking at this right now and trying to learn what I can: https://www.learncpp.com/cpp-tutorial/introduction-to-these-tutorials/
    Is my goal of learning this a realistic one?
    Thanks
     
  2. Sumner

    Sumner TrainBoard Member

    490
    425
    9
    I think I'd just work with C as it pertains to the Arduino. A number of YouTubes and other sources begin with very simple concepts and build from there using the Arduino as you go. Get one of the Arduino starter kits...

    https://www.google.com/search?q=ard...hrome.0.0l8.1469j0j7&sourceid=chrome&ie=UTF-8

    If you are actually doing something from the beginning vs. just trying to learn how to code I think you will find it more motivating. With one of these kits you would also have a separate Arduino to work with leaving your DCC++ system up and running,

    Sumner
     
    Uncle peanut butter likes this.
  3. FlightRisk

    FlightRisk TrainBoard Member

    311
    103
    5
    I agree that a primer is great because you have to understand a few concepts, but then look at the code a piece at a time and lookup questions like, "what is the C++ += operator do", then go back and check it out. Play by sticking code in an online compiler like this one https://www.learn-cpp.org/ or this one http://cpp.sh/. Not sure how well you like the link you posted, but there is also https://www.learn-cpp.org/. And if you are visual, videos of course.

    Then if you need help, post code from our GitHub repository here and ask for a breakdown of what it does. The hardest things (I think) for a someone new to learn are the binary math we need to use and pointers (the "address" that tells you where that object is stored vs. object itself). Example of maybe worst case for you:

    binary math:

    b[1]=((((DecoderAddress/64)%8)<<4) + (DecoderSubaddress%4<<1) + Activate%2) ^ 0xF8;

    Total gibberish! LOL. But if you draw 1's and 0's on a page to see how it is just manipulating those "bits" in a "byte" of 8 of them, you can see what it is doing. I need to do this myself all the time. So you have to learn that the % does a modulo calculation (give you the remainder of a division 5%3=2). And the << operator is shift left. So we shift those bits over to the left by 4 positions (00000011 becomes 00110000). And the last operation is a logical XOR or "exclusive or" function which is used to put the 1s and 0s in a particular pattern. And 0xF8 is a shorthand in hex to represent "11111000" (our pattern to mask against). It is actually easy to work in 2s once you get the hang of it. But maybe you are a mathematician and already know a lot of this!

    The normal processes of "if this, do that" and store this here and add these things together are relatively easy to do. So the general learning of C++ can be pretty quick and painless, but understanding code someone else has written is not as easy without comments in the code or you posting here the snippets and we can dissect it for you.
     
  4. Uncle peanut butter

    Uncle peanut butter TrainBoard Member

    26
    19
    2
    Not really committed to the lessons I linked to but once I get deeper in I’d like to stay with one teaching method.
    My main interest is to be able to run servo motors for turnout control.
    Therefore I need to be able to tell the command station which servo to address, tell the servo how many degrees to rotate, how much time will that rotation take etc.
    I know there are sketches readily available and in the end I will most likely use those as the parameters mentioned above have already been worked out. I want to try to understand what it is that’s going on, where the parameters are in the sketch and how do I change them.
    The Linux district I use has a text compiler called Geany. Will this work for me. It looks to me like it would but I’m not sure. As for math, it’s not one of my strongest attributes but I do have a fairly decent logical mind.
     
  5. Doug Gosha

    Doug Gosha TrainBoard Member

    1,331
    1,043
    31
    I learned C++ in 1998 because certain parties at work thought it would make the hearing aid test program run faster than it did programmed with Pascal which is what my cohort used to write it. We tried to explain that the hearing aid reaction time is what controlled the test time but, to no avail.

    So, I learned it and never used it. Oh well, the company paid for it.

    Doug
     

Share This Page