Topic: Firmware FilaWinder Study
I begin to study the filawinder firmware.. and i've some question...
at the beginning of main file there is..
//Variables for moving the guide
float guide_min = EEPROM.read(2); //Right limit for filament guide
float guide_max = EEPROM.read(1); //Left Limit for Filamnet guide
and some after this float are used by
**********************************
if (digitalRead(3) == 0 && digitalRead(8) == 1) { //If guide max nutton is pressed go to calibrate_max
//calibrate_max will loop while the button is held down.
calibrate_max(); //When the button is let up it will return here and write the
EEPROM.write(1, guide_max); //new value to the EEPROM
}
if (digitalRead(8) == 0 && digitalRead(3) ==1) { //If guide min button is pressed go to guide min
calibrate_min();
EEPROM.write(2, guide_min);
}
*************************************
but i've read on the arduino reference the eeprom write or read..
arduino.cc/en/Reference/EEPROMWrite#.UweIoIW_icE
work with A BYTE... and the float value (from the same reference) is 4 bytes...
arduino.cc/en/Reference/Float#.UweL3IW_icE
so it's possible you write in eeprom only a little piece of this float.. is true?
on the arduino forum i've found this post..
forum.arduino.cc/index.php/topic,41497.0.html
this explain how write float or double value (4 byte value) with a example..
Writing float values to Eeprom
****************************
#include <EEPROM.h>
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;
}
double testInt[12] = { -12.5, -10.00, -5.7, 0, 2.45, 2.90, 3.10, 4 , 5.6, 7.9, 5.5, 4};
byte noElem = 12;
unsigned int baseAddr = 0;
unsigned int n = 0;
void setup() {
Serial.begin(9600);
// write data to eeprom
for (int i=0; i <= noElem-1; i++){
n = EEPROM_writeAnything( (i*4)+baseAddr, testInt[i]);
}
// read data back
for (int i=0; i <= noElem-1; i++){
double val;
int addr = (i*4)+baseAddr;
n = EEPROM_readAnything( addr, val);
Serial.println(val);
}
}
void loop() {
}
*******************************
I'm right or i'm wrong and the eeprom.write can work with 4 byte alone ?
thx