Go Down

### Topic: How can i write/read an integer to eeprom? (Read 2293 times)previous topic - next topic

#### acmilangr

##### May 15, 2010, 08:31 pm
int temp;

how can i write to eeprom the content of temp? what if it has more than 1 digit? for example "123"
does the code need to split to 1,2,3 and write to 3 adresses?

#### AWOL

#1
##### May 15, 2010, 08:33 pm
123 is less than 255 which is the largest value you can store in a byte.
However "123" is a string and takes up four bytes.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### acmilangr

#2
##### May 15, 2010, 08:56 pmLast Edit: May 15, 2010, 08:59 pm by acmilangr Reason: 1
yeah mistake i mean 123 not "123"

and what is the syntax to do that?
do i need to split it and write 6,5,4 in 3 addresses? and how can i join them?(on reading)

#### AWOL

#3
##### May 15, 2010, 08:59 pm
Code: [Select]
`int x = 645;byte hix = highByte (x);byte lox = lowByte (x);`
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### acmilangr

#4
##### May 15, 2010, 09:04 pmLast Edit: May 15, 2010, 09:35 pm by acmilangr Reason: 1
Code: [Select]
`int x = 645;byte hix = highByte (x);byte lox = lowByte (x); `

thanks for that, a little explain? :-? what value will have the hix and what the lox on this example?

mmm is the split of 645 in 2 bytes?

searching on the internet i saw this
elocity = -200 = hex FF38 = [hex FF] [hex 38] = [255] [56]
Radius = 500 = hex 01F4 = [hex 01] [hex F4] = [1] [244]

so i think i undestand now..

and another question. do i need to check a demical if it is >than 256 to use high/low fuction before i save it to eeprom? and how do i know when i read from eeprom if the value have 1 or 2 addreesses? if i read always 2 adresses then if the number i saved was less than 256 i'll get wrong result

and how i merge them?

#### AWOL

#5
##### May 15, 2010, 09:41 pm
(hix * 256) + lox
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### retrolefty

#6
##### May 15, 2010, 09:55 pmLast Edit: May 15, 2010, 09:59 pm by retrolefty Reason: 1
and another question. do i need to check a demical if it is >than 256 to use high/low fuction before i save it to eeprom?

Integers have no decimal point.

and how do i know when i read from eeprom if the value have 1 or 2 addresses?

eeproms only directly write or read to byte addresses, so you always have to write or read two bytes to save or retrieve a integer number no matter what it's value is.

if i read always 2 addresses then if the number i saved was less than 256 i'll get wrong result

No you will get correct results (even if <256) if you use AWOL's formula,  x= (hix * 256) + lox;

Lefty

#### mowcius

#7
##### May 16, 2010, 11:21 pm
search for eepromwriteanything.

Mowcius

Go Up