Pages: [1]   Go Down
Author Topic: Find Min and Max from EEPROM stored data  (Read 340 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello crazy arduino fans...

As the title says, I am looking a way to find the min and max values of 500 data the has been stored into the internal EEPROM of arduino.
Please advice

Regards
Oldnick
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49302
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read the first value. Store it as both min and max value. Read each of the other values. If the value read is less than min, reset min. If the value read is greater than max, reset max.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  min=MAX_VAR; //reset minimum to the max
  max=MIN_VAR; //reset the max to the minimum
  for (index = 0; index < 500; index++) {
    var = read_eeprom(index); //read from the eeprom
    min=(var < min)?var:min; //revise min if min<var
    max=(var>max)?var:max; //revise max
  }

Just tailor to your applications
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks dhenry.Your code with some changes was OK.

BUT how I can store and after read in internal EEPROM float numbers (negative and possitive).
That is my code for write
Code:
#include <EEPROM.h>
#include "EEPROMAnything.h"

void setup(){
}
void loop()
{
 
  //for (int i=0; i < noElem-1; i++){
    EEPROM_writeAnything(0, -12.5);
    delay(500);
    EEPROM_writeAnything(1, -10.00);
    delay(500);
    EEPROM_writeAnything(2, -5.7);
    delay(500);
    EEPROM_writeAnything(3, 0);
    delay(500);
    EEPROM_writeAnything(4, 2.90);
    delay(500);
    EEPROM_writeAnything(5, 4);
    delay(500);
    EEPROM_writeAnything(6, 5.5);
    delay(500);
   
}

and that is the code for reading the data
Code:
#include <EEPROM.h>
#include "EEPROMAnything.h"

int address = 0;
float value;

void setup()
{
  // initialize serial and wait for port to open:
  Serial.begin(9600);
 }

void loop()
{
  // read a byte from the current address of the EEPROM
  EEPROM_readAnything(address,value);
 
  Serial.print(address);
  Serial.print("\t");
  Serial.print(value);
  Serial.println();
 

  address = address + 1;

  if (address == 512)
    address = 0;
   
  delay(500);
}

I can read correct the data

Pease advice
Oldnick
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49302
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    EEPROM_writeAnything(0, -12.5);
    delay(500);
    EEPROM_writeAnything(1, -10.00);
    delay(500);
    EEPROM_writeAnything(2, -5.7);
    delay(500);
    EEPROM_writeAnything(3, 0);
    delay(500);
    EEPROM_writeAnything(4, 2.90);
    delay(500);
    EEPROM_writeAnything(5, 4);
    delay(500);
    EEPROM_writeAnything(6, 5.5);
How are you fitting 4 bytes per byte of EEPROM?

The EEPROM_writeAnything method returns a value that might be important to you. It is the next address you can write to.

Code:
  EEPROM_readAnything(address,value);
 
  Serial.print(address);
  Serial.print("\t");
  Serial.print(value);
  Serial.println();
 

  address = address + 1;
You can't read a float from one byte.

Quote
I can read correct the data
I'm going to guess that a period is not the only thing missing from this sentence. "not" belongs in there some where.
Logged

Pages: [1]   Go Up
Jump to: