44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
float average(int anaPin) {
|
|
int lecturas = 10;
|
|
long total = 0;
|
|
float average = 0;
|
|
for(int i=0; i<lecturas; i++)
|
|
{
|
|
//delay(1);
|
|
total = total + analogRead(anaPin);
|
|
}
|
|
average = (float)total / lecturas;
|
|
return(average);
|
|
}
|
|
|
|
int decimal(float temp)
|
|
{
|
|
return((int)((temp-(int)(temp))*100));
|
|
}
|
|
|
|
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
|
|
Wire.beginTransmission(deviceaddress);
|
|
Wire.write((int)(eeaddress >> 8)); // MSB
|
|
Wire.write((int)(eeaddress & 0xFF)); // LSB
|
|
Wire.write(data);
|
|
Wire.endTransmission();
|
|
delay(4);
|
|
}
|
|
|
|
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
|
|
byte rdata = 0xFF;
|
|
Wire.beginTransmission(deviceaddress);
|
|
Wire.write((int)(eeaddress >> 8)); // MSB
|
|
Wire.write((int)(eeaddress & 0xFF)); // LSB
|
|
Wire.endTransmission();
|
|
Wire.requestFrom(deviceaddress,1);
|
|
while (!Wire.available()); rdata = Wire.read();
|
|
//if (Wire.available()); rdata = Wire.read();
|
|
return rdata;
|
|
}
|
|
|
|
float mapfloat(long x, long in_min, long in_max, long out_min, long out_max)
|
|
{
|
|
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
|
|
}
|