var ret = writeEEPROM(6, 20, "Hallo Test!"); //write the string
"Hallo Test!" into 20 bytes starting at position 4
print("Write str: " + ret);
//console output: Write str: 11
ret = writeEEPROM(26, 1, true); //write a bool into 1 byte at
position 26
print("Write b: " + ret);
//console output: Write b: 1
ret = writeEEPROM(27, 1, -1); //write the number -1 (minus 1)
into 1 byte at position 27
print("Write minus1: " + ret);
//Write minus1: 1
ret = writeEEPROM(28, 2, 0x55); //write the number 0x55 into 2
bytes starting at position 28
print("Write 16bit 0x55: " + ret);
//console output: Write 16bit 0x55: 2
The writeEEPROM function allows reading values from EEPROM. The maximum usable
EEPROM size is 28672 bytes.
Prototype:
var value = readEEPROM(number EEPROM_ADDRESS, number LENGTH,
string OPTIONAL_DATATYPE);
Parameters:
·
EEPROM_ADDRESS: The start address in the EEPROM to read the data from
·
LENGTH: The data length. The following rules apply:
? If reading a bool, the length will be ignored and 1 is always used
? If reading a number, the length needs to be 1, 2, 3 or 4
? EEPROM_ADDRESS + length may not be greater than max EEPROM size (28672)
·
OPTIONAL_DATATYPE: This is a hint about the type of data that shall be read. The
readEEPROM function will try to use the correct data type as its return value. If this
parameter is ommited or a non supported value is used, a byte array will be used as return
type (see Return value below)
? Possible values:
? “bool”
? “number”
? “string”
·
Return value (value): In case reading failed, undefined will be returned (observe console
error messages when testing the project). If reading worked, the value that was read from
EEPROM will be returned. The data type of the returned value depends on
OPTIONAL_DATATYPE parameter. If this parameter was omitted, a byte array object is
returned that contains the single data bytes of the EEPROM (as numbers).
Note: The written and returned numbers are treated as signed 32Bit integers
regardless of the actual data length! If e.g. -1 is written with a length of 1 and then