Update 3 Jan. 2016: I have answered my own question now too.
I need some help formatting my "if" statement in this C++ macro please:
#define updateEEPROMVal(address,val) if (EEPROM.get(address)!=val) \
EEPROM.put(address,val)
I'm getting pages of errors, so I'm assuming it's a simple formatting problem.
Update Apr. 2020: Jump straight to my answer. My macro was fine (surrounding it with do {} while (false)
would have been better of course, but it was fine as-is). I was simply forgetting the 2nd parameter in EEPROM.get()
is all. The 2nd parameter is passed by NON-const
C++ reference, and at the time I didn't really know what a reference was or how it worked, so I didn't use the .get()
method correctly. That's it!
Back to my original question from 2016:
Here's the full context:
//----------------------------------------------------------------------------------------------------------------------------------
//storeXYValsIntoEEPROM
//-store the current global variable x and y low, center, and high values into EEPROM
//----------------------------------------------------------------------------------------------------------------------------------
#define updateEEPROMVal(address,val) if (EEPROM.get(address)!=val) \
EEPROM.put(address,val)
void storeXYValsIntoEEPROM()
{
//update EEPROM values *only* if necessary, this way you minimize writes (and wear-and-tear) on the EEPROM, since it is limited to
//100k writes per cell I believe (see datasheet)
updateEEPROMVal(0,x_low);
updateEEPROMVal(2,x_ctr);
updateEEPROMVal(4,x_high);
updateEEPROMVal(6,y_low);
updateEEPROMVal(8,y_ctr);
updateEEPROMVal(10,y_high);
}
UPDATE: HERE's my error output:
Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"
Using library IRremote in folder: C:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\IRremote (legacy)
Using library eRCaGuy_ButtonReader in folder: C:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\eRCaGuy_ButtonReader (legacy)
Using library EEPROM in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\IRremote -IC:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\eRCaGuy_ButtonReader -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM C:\Users\Gabriel\AppData\Local\Temp\build6111239347405487460.tmp\IR_Tx_code5_w_calibration_mode.cpp -o C:\Users\Gabriel\AppData\Local\Temp\build6111239347405487460.tmp\IR_Tx_code5_w_calibration_mode.cpp.o
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:43:30: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
operator const uint8_t() const { return **this; }
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:92:26: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
operator const int() const { return index; }
^
IR_Tx_code5_w_calibration_mode.ino: In function 'void storeXYValsIntoEEPROM()':
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:436:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:436:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:436:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:437:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:437:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:437:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:438:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:438:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:438:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:439:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:439:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:439:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:440:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:440:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:440:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:441:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:441:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:441:3: note: in expansion of macro 'updateEEPROMVal'
Multiple libraries were found for "IRremote.h"
Used: C:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\IRremote
Not used: C:\Program Files (x86)\Arduino\libraries\RobotIRremote
no matching function for call to 'EEPROMClass::get(int)'