Hello, cannot find information so hope you can explain me.
We have to methods of reading from memory EEPROM.read which reads single byte and EEPROM.get which reads the number of bytes equal to the type of variable we are reading to.
If you compile such code:
#include <EEPROM.h>
byte variable1 = EEPROM.read(10);
void setup() {
//any code here
variable1 += 5; //doesn't matter what here is just for the purpose of an example
}
void loop() {
//any code here
}
as you can see I use EEPROM.read outside of any function and compiler considers it to be appropriate. But if I compile such code:
#include <EEPROM.h>
long variable1;
EEPROM.get(20, variable1);
void setup() {
//any code here
variable1 += 5; //doesn't matter what here is just for the purpose of an example
}
void loop() {
//any code here
}
compiler considers it to be error using EEPROM.get outside of a function, so I need
#include <EEPROM.h>
long variable1;
void setup() {
//any code here
EEPROM.get(20, variable1);
variable1 += 5; //doesn't matter what here is just for the purpose of an example
}
void loop() {
//any code here
}
As for the purpose of the post it is the first thing pure curiosity why this way not other and the second thing wanted to declare global variables in one block and I see I need to do it partially in void setup