I'm trying to create a simple application that stores a struct in the EEPROM memory and on startup it reads the stored struct from the EEPROM and then executes the rest based on the stored data.
This is my main ino file:
extern "C" {
#include "Structs.h"
}
Settings settings;
void setup()
{
settings = settings_read();
}
void loop()
{
/* add main program code here */
}
This is the Structs.h
file:
#ifndef _STRUCTS_h
#define _STRUCTS_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
typedef struct {
byte lastCountry;
byte lastMode;
} Settings;
#endif
This is the Settings.ino
file:
#include <EEPROM.h>
Settings settings_read() {
byte country, mode;
Settings settings;
country = EEPROM.read(0);
mode = EEPROM.read(1);
settings = {
country,
mode
};
return settings;
}
This is the compiler error:
Compiling 'Stoplicht' for 'Arduino Uno'
Stoplicht.ino:5:1: error: 'Settings' does not name a type
Stoplicht.ino:In function 'void setup()'
Stoplicht.ino:9:27: error: 'settings_read' was not declared in this scope
Error compiling
I tried a lot of different things to get this to work. I tried putting the code from Settings.ino
into a .C file. That gave more error's and it said the EEPROM.h
function were not declared. I also tried putting the struct
and settings_read
into Settings.ino
that gave even more errors. I'm completely new to C, I just can't find what I'm doing wrong here.