Skip to main content
Improved formating
Source Link
Greenonline
  • 3.1k
  • 7
  • 34
  • 48

Since Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly. Then

Then you can get rid of all ifif statements. To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus:

EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

And to retrieve the value:

EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);
f = (float) (f / 10.0);

Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly. Then you can get rid of all if statements. To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus:

EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

And to retrieve the value:

EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);
f = (float) (f / 10.0);

Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly.

Then you can get rid of all if statements. To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus:

EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

And to retrieve the value:

EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);
f = (float) (f / 10.0);

SinceSince your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly.

Than Then you can get rid of all if statements.

  To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int)(so adding + 0.5 before converting to an int).

Thus: EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

And to retrieve the value: EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f); f = (float) (f / 10.0);

EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);
f = (float) (f / 10.0);

Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly.

Than you can get rid of all if statements.

  To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus: EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

And to retrieve the value: EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f); f = (float) (f / 10.0);

Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly. Then you can get rid of all if statements. To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus:

EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

And to retrieve the value:

EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);
f = (float) (f / 10.0);
deleted 19 characters in body
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 17

Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value uptoup to 15.0 (resulting in 150 int), you can use a simple byte and store it in EPROMEEPROM directly.

Than you can get rid of all if statements.

To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus: EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

 EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

andAnd to retrieve the value: EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f); f = (float) (f / 10.0);

EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);

f = (float) (f / 10.0);

Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value upto 15.0 (resulting in 150 int), you can use a simple byte and store it in EPROM directly.

Than you can get rid of all if statements.

To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus

 EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

and to retrieve the value:

EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);

f = (float) (f / 10.0);

Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly.

Than you can get rid of all if statements.

To make a better formula, you can even add rounding (so adding + 0.5 before converting to an int).

Thus: EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);

And to retrieve the value: EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f); f = (float) (f / 10.0);

Source Link
Michel Keijzers
  • 13k
  • 7
  • 40
  • 58
Loading