# Negative number using EEPROMWriteAnything?

**URL:** <https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102>\
**Category:** Programming\
**Created:** [August 6, 2012, 6:48pm UTC](https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102 "2012-08-06T18:48:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 6, 2012, 6:48pm UTC](https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102/1 "2012-08-06T18:48:04Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![wildbill](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wildbill/32/1126438_2.png) [@wildbill](https://forum.arduino.cc/u/wildbill)\
**Post date:** [August 6, 2012, 6:53pm UTC](https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102/2 "2012-08-06T18:53:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 6, 2012, 6:54pm UTC](https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102/3 "2012-08-06T18:54:33Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 6, 2012, 9:35pm UTC](https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102/4 "2012-08-06T21:35:06Z")

</div>

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

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

//Epprom map values
int BPFRMv;
int BPTOv;

```

In Setup i set these

```cpp
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)

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

```

Then i use them in the loop

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

```

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

Thanks  
Andy

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 7, 2012, 9:46am UTC](https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102/5 "2012-08-07T09:46:04Z")

</div>

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

```cpp
EEPROM_writeAnything(BPFRM, -20);

```

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

```cpp
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.

```cpp
BPTOv = EEPROM_readAnything(BPTO, BPTOv);

```

Then, you similarly crap all over BPTOv.

```cpp
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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 7:53pm UTC](https://forum.arduino.cc/t/negative-number-using-eepromwriteanything/115102/6 "2021-05-05T19:53:26Z")

</div>

Closed on May 5, 2021, 7:53pm UTC


