Pages: [1]   Go Down
Author Topic: Code won't compile  (Read 3771 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The following sketch will compile in version 21 and below, but not in version 22. Any ideas?
It writes multiple bytes to EEPROM. Been running it for some time in a larger sketch. Upgraded to version 22 yesterday.

#include <EEPROM.h>
float Kwh = 141.00;
float KwhHourstart = 0.000;
float KwhDaystart = 141.000;
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
    const byte* p = (const byte*)(const void*)&value;
    int i;
    for (i = 0; i < sizeof(value); i++)
        EEPROM.write(ee++, *p++);
    return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
    byte* p = (byte*)(void*)&value;
    int i;
    for (i = 0; i < sizeof(value); i++)
        *p++ = EEPROM.read(ee++);
    return i;
}

void setup()
{
    Serial.begin(9600);
    EEPROM_writeAnything(20, Kwh);
    EEPROM_writeAnything(24, KwhHourstart);
    EEPROM_writeAnything(28, KwhDaystart);
    EEPROM_readAnything(20,Kwh);
    Serial.print(Kwh,3);
    
    
}
void loop()
{
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 630
Posts: 49998
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This has been discussed here, before. No conclusions drawn/posted as to why, but a workaround was defined.

You need to put the template stuff in a .h file, and include that in the sketch.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks... was not aware of a previous post.
Logged

Pages: [1]   Go Up
Jump to: