4

For the fucks sake, friend sent me code with ton of shit like that:
digitalWrite(room6,lv6);}
Is there some nice short guideline how to wire nice clean Arduino/C-based languages?

Comments
  • 1
    Usually, you encapsulate this physical stuff into some logical units, i.e. a hardware abstraction layer. This "digital write" thing is a register wrapper, but not an abstraction layer.

    Say you have a motor control, then you would write functions for turning the motor on and off, possibly with some safety checks, getting and setting its speed and such. The rest of the application wouldn't even know that e.g. setting the speed involves some PWM.
  • 1
    @Fast-Nop this is GREAT, but I need him to stop doing crap like:
    void function(){foo();}
    Is there some nice short document with examples showing how you should generally write?
  • 1
    @TheLastGimbus well that is not even C related (resp. C++ because Arduino is C++), it would be the same in any language.

    Such crap code shows that your buddy has no understanding what he is doing. It will be even worse with any kind of data structure. Means, he will have to learn programming for real, or else it will be a whack-a-mole game. It will be a lot of work for him.

    I think "The Practice of Programming" by Kernighan and Pike would be a good choice.
  • 1
    @Fast-Nop he is using Arduino only for help with his DIY stuff, and he probably doesn't plan any IT career, but, fuck, he often asks me where he did mistake, but I can't even read it...
  • 1
    In that case, the number 1 thing that you should teach him is state machines. That's what you mostly need for these projects. Let him draw this stuff on a piece of paper before even starting to code. And then teach him how to implement that. You know, the while loop with the switch statement. That will bring him already a long way.
Add Comment