Reusing Code-Programming Tip For Beginner's

microcontrollerusermicrocontrolleruser Posts: 1,194
edited 2018-05-28 - 12:55:03 in Microcontrollers
Make a template that you can open in a new project for the controller.

Later you can start saving templates after working with LED's, serial communication, writing to EEPROM etc.

If nothing else just use the code you were working on last project to start new project.

That way you write less lines of new code to achieve the goal.


  • You may be summoning the famous JonnyMac in this thread, AKA King of Propellers (KoP) and King of BASIC Stamps (KoBS) and the master provisioner of programming templates.

    Ken Gracey

  • Thanks!

    In a way you can keep using the same program over and over again.

    Unless you change controller.

    Just saying 'Today with my processor and program I will control this.'
  • JonnyMacJonnyMac Posts: 7,311
    edited 2018-05-28 - 04:08:40
    As Ken points out, I am believer in using templates. I have attached programming templates for the BS1, BS2, and a couple for the Propeller. I have dozens of templates, usually tailored to a specific platform. At EFX-TEK we have several Propeller-based products, so most of my templates are focused there (yes, we release templates for our products so that our customers can hack them). The HC-8+ is our go-to controller so I have a lot of templates for it, most devoted to specific types of apps. I have attached the generic template which is where I start with custom projects for that board.

  • Point I am making for beginners is this .

    You will see things like this in tutorials and books.

    'Now change the code to have LED's blink on and off alternating'

    'Reusable code' 'Routines'

    You WILL get to the point where you reuse a lot of code.

    Just adding the parts that are new for the task at hand.
  • You



  • Hi

    I don't exactly use a template- but I take the source code for an old program- "save as" a new file name- comment out all code apart from copper plate- then start new code and use the commented out code to remember the syntax.

    Works for me.

    Later I can delete the commented out code


  • Good point about 'save as'.

    As far as libraries.That's too advanced for beginner's.

    You have to see things from their viewpoint.

    The idea is to help not throw a bunch of stuff at them.

    The basic idea is that when when they see 'Now change the program to this' that will be

    important later. In various forms.
  • microcontrollerusermicrocontrolleruser Posts: 1,194
    edited 2018-05-28 - 13:08:32
    For beginners.

    Libraries are sections of code that perform a purpose.

    That you can paste into your program or call in a new program you write.

    Doing that way is less work than writing it all over again.

    Myself I prefer to write my own libraries.For a lot of reasons.

    You just save what you have done all along and you accumulate code you can use later.

    For beginners it is better to say 'Save code to use later in another program' than throw a new concept at them.

  • WhitWhit Posts: 4,154
    edited 2018-05-29 - 14:29:28
    @microcontrolleruser - great thread! I linked this thread to one I began. You might enjoy it - see

    @JonnyMac - thanks for posting your templates.

  • Thank you Whit!

    Thank you Johnny!

    That is a good post of yours.

    About reusing code. I think everybody comes up with little variations of it.

    The basic concept is shared though.Cut and paste before editing.
  • WhitWhit Posts: 4,154
    edited 2018-05-29 - 20:39:15
    @microcontrolleruser - that is Jon or JonnyMac - thought I’d beat him to the punch! :-)

    See Jon's signature line...
Sign In or Register to comment.