Hey guys,
I'm pretty new to Arduino, but have been doing okay so far. I am having a quite a bit of trouble writing a library function that reads and writes to the EEPROM. The project is an RFID door opener, I want the ability to add cards to the non-volatile memory if one's detected while the button is pressed, or check the card against the memory to allow entrance if the button is not depressed. The DataBase lib I'm writing should roughly do this, but I keep getting an error saying "'EEPROM' was not declared in this scope" even though it's in the header.
Everythings work in progress but I can't get past this bug! thanks for taking the time to read though it and any help you can give.. I'm also confused that despite updating to 1.01 I still need to include 'Arduino.h' for it to work. in the library tutorial it said it should run off 'WProgram.h' instead. only mention as maybe I fluffed the update.
My code structure is as follows: folder 'database' contains:
'database.ino' (with nothing in it)
'DataBase.h'
#ifndef DataBase_h
#define DataBase_h
#include <EEPROM.h> // DEFINITION RIGHT HERE :(
#include <Arduino.h>
class DataBase {
public:
DataBase();
~DataBase();
boolean existsAt(int i); // checks EEPROM to see if position is taken.
int existsValue(int value[5]); // checks EEPROM
int getAt(int i); // returns array
void setAt(int i, int value[5]);// set in EEPROM
void clearAt(int i); // deletes in EEPROM
};
#endif
'DataBase.cpp'
#include "DataBase.h"
DataBase::DataBase(){
Serial.begin(9600);
}
DataBase::~DataBase(){
}
boolean DataBase::existsAt(int i){
i*=8;
boolean t = false;
for (int j=i; j<i+8; j++){
if(EEPROM.read(j)!=255){ // BUG HERE :(
t=true;
}
}
return t;
}
int DataBase::existsValue(int value[5]){
for ( int i=0; i<1024/8; i+=1){
if(existsAt(i)&&getAt(i)==value){
return i;
}
}
return -1;
}
int* DataBase::getAt(int i){
int ans[5];
i*=8;
for (int j=i; j<i+8; j+=2){
int[(j-i)/2] = int(EEPROM.read(j)) + int(EEPROM.read(j+1));
}
return ans;
}
void DataBase::setAt(int i, int value[5]){
i*=8;
for (int j=i; j<i+8; j+=2){
byte a = 0;
byte b = 0;
if(value>255){
a = 255;
b = value-255;
}
EEPROM.write(j , a );
EEPROM.write(j+1, b );
}
}
void DataBase::clearAt(int i){
i*=8;
for (int j=i; j<i+8; j+=2){
EEPROM.write(j , a );
EEPROM.write(j+1, b );
}
}