-
Notifications
You must be signed in to change notification settings - Fork 138
Constructor
A constructor is a special kind of class member function that is executed when an object of that class is instantiated. Constructors are typically used to initialize member variables/functions of the class to appropriate default values, or to allow the user to easily initialize those member variables/functions to whatever values are desired.1
-
The constructor must be called before
void setup()
. The constructor can be any word of your choice.For example, the library can called by declaring
#include SPIFlash.h SPIFlash flash; void setup() { ... }
where 'flash' can be replaced by a user constructor of choice.
-
The constructor is used to call a function from the SPIFlash library.
For example, in the code below, to call the
readByte()
function from the SPIFlash library, the line of code used isflash.readByte(...)
#include<SPIFlash.h> SPIFlash flash; //This is the constructor. This example uses 'flash' as the constructor void setup() { ... } void loop() { flash.readByte(...) //The constructor 'flash' is used to call the function 'readByte()' from the library ... }
- The library can also called by declaring the
SPIFlash flash(csPin*)
constructor where 'flash' can be replaced by a user constructor of choice and 'csPin' is the Chip Select pin for the flash module.
For example the following code sets up the library to use the pin 33 as the Chip Select pin.
#include SPIFlash.h
SPIFlash flash(33);
void setup() {
...
}
IMPORTANT: the csPin must be declared if using a non-default SPI interface.
* NOTE: This is currently only supported on the SAMD and STM32 architectures.
-
All versions of the library >= v3.0.0 support the ability to use any of multiple SPI interfaces (if your µC supports them).
For example the following code sets up the library to use the
SPI1
SPI interface instead of the defaultSPI0
.#include SPIFlash.h SPIFlash flash(33, &SPI1); void setup() { ... }
SPIFlash Library for Arduino
© Prajwal Bhattaram under the GNU GPLv3 License
Wiki status: Up to date: 08.03.2018