Reusing Code-Programming Tip For Beginner's
microcontrolleruser
Posts: 1,194
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.
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.
Comments
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.'
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.
just
invented
libraries?
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
Dave
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.
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.
@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.
See Jon's signature line...