I know there are codes which deals with showing of current gear in this forum, but anyway, here is one more.
In short, this code is written for motorbike shifting sequence 1-N-2-3-4-5-6, has ability to change brightness of 7-segment LED display with gear-lever, and stores values in EEPROM. More is written as notes in code itself.
Please note, that’s my first project, so please be nice to me
I hope it helps someone who is looking for such DIY motorbike improvement.
Any suggestions are highly appreciated
The code is in attached text file (including notes is too long to shown here - forum policy)
gear_indicator_code.txt (8.5 KB)
My criticism is
- some of the lines are very long
- You could break it down into smaller functions rather than putting all the code in one big lump
'Program'/'app'/'sketch'/'script' are nouns for pieces of software, code is not (in fact it means roughly
the same as the word software (but less abstract) - except when talking about code breaking or character encodings).
Thus "some code", "my code", "a piece of code", "glue code" but not "a code" or "there are codes"
It comes from the early days of transcribing an algorithm into machine code, assembly and so
forth, which involved "coding up". What you code up is an algorithm, program, utility, etc etc.
The word code has another more technical meaning - every program consists of code and data,
where the code is the part that is instructions and calculation, and the data is just values (numbers/
strings/whatever). Code is behaviour/computation, data is passive/values
To point 1 - long lines. They are long because the comments, or scripts themselves are long? If notes, I expected everyone will delete them before implementation.
Point 2 - will try to tidy it up.
Thanks for grammar advice. I'm not english native speaker, so I just used translation without thinking about it (code has little different meaning/usage in my language). BTW, what about source code, or just source?
byte i; //current gear counter
byte j; //new gear counter
byte k; //brightness counter
Those are global variables; give them sensible names like currGearCnt, newGearCnt etc. If they are not counters, don't add the 'Cnt'.
Never use one character names for global variables. Personally I also don't even use them in loops.