So the eeprom holds 0 to 255. with numbers that begin with 0, the 0 gets chopped off when I read it back.
What do I do?
#include <EEPROM.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
EEPROM.write(16, 01);
Serial.println(EEPROM.read(16));
EEPROM.write(16, 10);
Serial.println(EEPROM.read(16));
delay(9999);
}
I'm afraid that the question is beyond my knoledge. Google says it means base 8. I'm not sure how to answer. So I will explain what i'm doing and perhaps you tell me what question i should be asking.
I have a number that ranges from 16 characters to 24 characters. Since eprom can handle numbers 0 to 255, I split my number into 8 chunks of either 2 digits or 2 digits (or a combination). so that I can store them in 8 blocks of the eeprom.
So lets say my number is 0193857263235671. It will be broken into 01 93 85 72 63 23 56 71 and each substring sent to a block of eprom. But when i read it back it comes back to me as 1 93 85 72 63 23 56 71. Note the leading 0 is gone.
thanks for the help. ill do the best i can to not be a noob.
Whilst it is true that the EEPROM holds data in bytes there is nothing stopping you from using the put() and get() functions to save and retrieve multiple bytes at the same time
Whilst it is true that the EEPROM holds data in bytes it is usually better to use the put() and get() functions to save and retrieve multiple bytes at the same time
birddseedd:
So will get instread of read save my leading zeros?
The leading zeroes are there but Serial.print() is not printing them. If you want them printed then you need to add them yourself if the 2 digit number is less than 10
At the root of the problem is a misunderstanding of how things actually work.
birddseedd:
So the eeprom holds 0 to 255.
Yes, the possible values are indeed 0 through 255.
with numbers that begin with 0, the 0 gets chopped off when I read it back.
That is because, in your case, the 0 does not affect the numerical value.
Let's say that you are at a bakery, and you order 01 bagel. You are then handed a bag containing 1 bagel. All is well.
The moral here is to think of numbers as quantities (like the number of bagels in a bag), rather than as arrangements of digits.
Just so you know, when you try using things like 010, or maybe even 08, in your code, Bad Things Happen. (The bakery clerk is not well-adjusted, and will interpret an order of 010 bagels as an order for 8 bagels. If you want 10 bagels, then specify 10, not 010.)