Go Down

Topic: the counter restart when the address reach 256 (Read 581 times) previous topic - next topic

chadect

Hello,

My code will saves data even there is no power so i used EEPROM.. but my porblem is.. when the counter reach the 256.. the counter reset to zero.. here is my codes.. i need a counter that can store up to 600.. thank you..




#include <EEPROM.h>


int addr;
int address;
const int button =2;
const int clearcounter= 3;
const int led = 12;
int state =0;
int clearcount=0;
int counter=0;
byte value;

void setup()
{
  pinMode(button, INPUT);
  pinMode(clearcount, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
    addr=EEPROM.read(address);
 
 
}


void loop()
{
delay(1000);
state= digitalRead(button);
if(state==HIGH)
{
delay(100);
 
  counter= EEPROM.read(addr)+1;
 
  EEPROM.write(addr, counter);
  Serial.println("WRITE");
Serial.print(addr);
  Serial.print("\t");
  Serial.print(counter, DEC);
  Serial.println("WRITE END ");
  Serial.println();
 
    // the EEPROM, so go back to 0 when we hit 512.

}
else if (state==LOW)
{
   
}
clearcount= digitalRead(clearcounter);
if(clearcount==HIGH)
{
  for (int i = 0; i < 512; i++)
    EEPROM.write(i, 0);
   
  // turn the LED on when we're done
  digitalWrite(13, HIGH);
    Serial.println("Clear");
}


 
}






 
  // advance to the next address.  there are 512 bytes in

Coding Badly


@chadect: Please do not cross-post.

All others: Please reply here...
http://arduino.cc/forum/index.php/topic,90170.msg677060.html

Go Up