TINY 85 EEPROM

Hi

I am new to arduino env.

I am trying to below program of password lock on Attiny85. But i am not able to write to EEPROM.

Anybody help me. Thanks in advance.

#include <AnalogMatrixKeypad.h>
#include <Password.h>
#include <EEPROM.h>

char* secretCode = "3456";

int analogPin = A1; // TINY 85 IC Pin No. 7 (IC Pin No.8 to 5V) Analog Signal from one wire keyboard
AnalogMatrixKeypad AnMatrixKeypad(analogPin);

Password password = Password (secretCode);
Password MstrPW = Password ("496321");

boolean locked = true;

int redPin = 5; // TINY 85 IC Pin No. 1 Not usable as it is reset pin, hence connected to closepin
int greenPin = 3; // TINY 85 IC Pin No. 2
int bluePin = 4; // TINY 85 IC Pin No. 3
int openpin = 1; // TINY 85 IC Pin No. 6
int closepin = 0; // TINY 85 IC Pin No. 5

int j=0;

void setup()
{
pinMode(redPin, OUTPUT);pinMode(greenPin, OUTPUT);pinMode(bluePin, OUTPUT);
pinMode(openpin, OUTPUT); pinMode(closepin, OUTPUT);
loadCode(); password.set(secretCode); flash(); updateOutputs();
}

void loop()
{
char key =AnMatrixKeypad.readKey();
if(key != KEY_NOT_PRESSED)
{
blnk();
switch (key)
{
case '*': selectpsw(); break;
case '#': locked=true; updateOutputs(); break;
default: password.append(key);MstrPW.append(key);j=j+1;
}
delay(10);
}
}

void selectpsw()
{
if (j==4) checkPassword();
if (j==6) checkMstrPW();
else if (j!=4 && j!=6 && j!=0)
{
flash();flash();updateOutputs();
}
}

void checkPassword()
{
j=0;
if (password.evaluate())
{
locked = false; password.reset(); MstrPW.reset(); updateOutputs();
}
else
{
password.reset();MstrPW.reset();flash();flash();
updateOutputs();
}
}

void checkMstrPW()
{
j=0;
if (MstrPW.evaluate()) {getNewCode();password.reset();MstrPW.reset();}
else
{password.reset();MstrPW.reset();updateOutputs();flash();flash();return; }
}

void blnk()
{ digitalWrite(bluePin,HIGH);delay(100);digitalWrite(bluePin,LOW); }

void flash()
{
digitalWrite(redPin,HIGH);delay(100);digitalWrite(redPin,LOW);
digitalWrite(greenPin,HIGH);delay(100);digitalWrite(greenPin,LOW);
digitalWrite(bluePin,HIGH);delay(100);digitalWrite(bluePin,LOW);
}

void updateOutputs()
{
j=0;
if (locked)
{
digitalWrite(redPin, HIGH);digitalWrite(greenPin, LOW);
digitalWrite(closepin,HIGH);delay(750);digitalWrite(closepin,LOW);

}
else
{
digitalWrite(redPin, LOW); digitalWrite(greenPin, HIGH);
digitalWrite(openpin,HIGH);delay(750);digitalWrite(openpin,LOW);
}
}

void loadCode()
{
if (EEPROM.read(0) == 7)
{secretCode[0] = EEPROM.read(1); secretCode[1] = EEPROM.read(2);
secretCode[2] = EEPROM.read(3); secretCode[3] = EEPROM.read(4);}
}

void saveCode()
{
EEPROM.write(1, secretCode[0]); EEPROM.write(2, secretCode[1]);
EEPROM.write(3, secretCode[2]); EEPROM.write(4, secretCode[3]);
EEPROM.write(0, 7);
locked = true; updateOutputs();flash();flash();flash();
}

void getNewCode()

{
flash();
for (int i = 0; i < 4; i++ )
{
char key;
key = AnMatrixKeypad.readKey();
if(key != KEY_NOT_PRESSED)
{
if (key != '*' && key != '#')
{secretCode = key; flash();}

  • else*
  • {i=-1;}*
  • }*
  • }*
  • saveCode();flash();flash();*
    }

But i am not able to write to EEPROM.

How do you know that?

ONE STATEMENT PER LINE!!!

i am not able to change the secretcode.

But i am able to change the code with same program on Atmega328.

why not on TINY 85. ?