-
Notifications
You must be signed in to change notification settings - Fork 138
Other functions
Prajwal Bhattaram edited this page Mar 7, 2018
·
1 revision
-
This function returns the size of a String to use as the argument in getAddress(size) - see below.
-
Using size = sizeof(String) will cause the getAddress(size) function to fail.
size = sizeof(_type_of_variable)
can be used for all types of data but String objects.
All addresses in the in the sketch must be obtained via this function or not at all.
- Gets the next available address for use.
- Takes the size of the data to be written as an argument and returns a 32-bit address.
- This function allocates the required amount of space for each variable it is called for and the addresses obtained via this function should not be used with another variable or the user runs the risk of corrupting their data.
#include SPIFlash.h
SPIFlash flash;
uin32_t byte_address, int_address, float_address, string_address, constant_address;
String _string = "This is a String";
struct Constant {
byte A = 64;
String B = "Test String";
float C = 3.14;
boolean D = false;
} Constant _constant;
void setup() {
flash.begin();
byte_address = flash.getAddress(sizeof(uint8_t));
int_address = flash.getAddress(sizeof(uint16_t));
float_address = flash.getAddress(sizeof(float));
string_address = flash.getAddress(flash.sizeofStr(_string));
constant_address = flash.getAddress(sizeof(_constant));
flash.writeByte(byte_address, 123);
flash.writeWord(int_address, 4567);
flash.writeFloat(float_address, 8.901);
flash.writeStr(string_address, _string);
flash.writeAnything(constant_address, _constant);
...
}
SPIFlash Library for Arduino
© Prajwal Bhattaram under the GNU GPLv3 License
Wiki status: Up to date: 08.03.2018