-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing to EEPROM using whitespace instead of spare zeros #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a neat idea.
Note, there's a bug in the overall loop counter, that puts the code into an infinite loop. Also, please consider some cosmetic improvements.
Serial.println("Programming EEPROM:"); | ||
|
||
// Go over all inputs | ||
for (byte i = 0; i < 256; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BUG: The comparison of the i variable with 256 is always true due to limited range of data type.
writeEEPROM(i + 512, (d2 == 0) ? 0 : digits[d2]); // write the digit or clear if 0 | ||
writeEEPROM(i + 256, (d2 == 0 && d3 == 0) ? 0 : digits[d3]); // write the digit or clear if d3 and d2 are 0 | ||
writeEEPROM(i, digits[i % 10]); // write the digit even 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier to show powers of two, when using hex notation, like this:
writeEEPROM(i + 0x300, blank); // clear first 7segment display
writeEEPROM(i + 0x200, (d2 == 0) ? blank : digits[d2]); // write the digit or clear if 0
writeEEPROM(i + 0x100, (d2 == 0 && d3 == 0) ? blank : digits[d3]); // write the digit or clear if d3 and d2 are 0
writeEEPROM(i + 0x000, digits[i % 10]); // write the digit even 0
void programmEEPROM() { | ||
byte digits[] = { 0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b }; | ||
byte minusSign = 0x01; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's define a white space for the display
byte blank = 0x00;
Then the code is more readable, where we compare d2 == 0, write blank.
Serial.println("%"); | ||
} | ||
|
||
// Non two's complement part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about labeling this as "Unsigned byte part"?
I've implemented a better-looking version for the EEPROM programmer using whitespace. So instead of "-009" it should be " -9". " 023" should now be " 23" and so on. Couldn't test it tho.