Negative number using EEPROMWriteAnything?

Hi, to make things a little easier (storing large and negative numbers) i came accross EEPROMWriteAnything?

and ive read in this post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1292673979 that negative numbers supposildy work but i cannot get them to?

If i send a negative number it basically sets it to 0?

Anyone be able to point me in the right direction?

Thanks Andy

Shouldn’t be an issue - post the code that’s exhibiting the problem.

Anyone be able to point me in the right direction?

Sure. Up there, above where you type, see the two rows of icons above the smiley faces? See the one with the # on it? Use that one, and post your code.

Whilst writing out the code i realised an error, which i really thought was the problem, but since fixing it it has now made it so the positive number doesnt work either.

My code is below and is very simple...

I Declare these

//Epprom Map Address's
int BPFRM = 0;
int BPTO = 10;

//Epprom map values
int BPFRMv;
int BPTOv;

In Setup i set these

EEPROM_writeAnything(BPFRM, -20);
EEPROM_writeAnything(BPTO, 20);

Then at the end of the setup i get them from the epprom them (this is where i found the problem, i was using BPFRMv for BOTH)

//Get maps from epprom
BPFRMv = EEPROM_readAnything(BPFRM, BPFRMv);
BPTOv = EEPROM_readAnything(BPTO, BPTOv);

Then i use them in the loop

BPV = map(analogRead(BPP), 0, 1023, BPFRMv, BPTOv);

The above seems to map the 0-1023 to 0-0???

Thanks Andy

"Snippets are us" is down the road a ways. Here, we need to see all of your code.

EEPROM_writeAnything(BPFRM, -20);

This should be writing the value -20 at address 0.

BPFRMv = EEPROM_readAnything(BPFRM, BPFRMv);

This is reading from address 0, and putting the result in BPFRMv. Then, it assigns the return value to BPFRMv, overwriting the value that it read from the EEPROM.

The return value is the number of bytes read. So, BPFRMv ends up containing 2.

BPTOv = EEPROM_readAnything(BPTO, BPTOv);

Then, you similarly crap all over BPTOv.

BPV = map(analogRead(BPP), 0, 1023, BPFRMv, BPTOv);

Psst. You to range has a size of 0, since both ends of the range are 2. The result, in the map function, will be a divide by 0, so the result of that division, and the whole map output, will be undefined.