Help me with a code

I have a proyect with a MLX90614(an ir infrared thermometer with I2c), and the output temperature is displayed in a oled 128x64 I2c, I am using an arduino pro mini, the code works well, but i want to add a function:

I want to press a button that saves the temperature shown, in the right down corner of the screen, and if I press it again to save again the temperature.

It is like a memory function, I searched on the internet and I discovered that there is a memory in the arduino called eeproom but i have problems combining that function with the code.

Any help appreciated. Thanks.

Code:

#include "U8glib.h"            // U8glib library for the OLED
#include <Wire.h>              // Wire library for I2C communication
#include <Adafruit_MLX90614.h> // MLX90614 library from Adafruit

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

//U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9, 8); // D0=13, D1=11, CS=10, DC=9, Reset=8
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C
U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9, 8);
void draw(void) 
{
  u8g.setFont(u8g_font_profont15r);        // select font
  u8g.drawStr(1, 12, "Object Temperature");// 
  u8g.setFont(u8g_font_profont29r);        // select font for temperature readings
  u8g.println("°C");                        // prints C for Celsius
  u8g.setPrintPos(35, 55);                 // set position
  u8g.println(mlx.readObjectTempC(), 0);   // display temperature from MLX90614
 Serial.println(mlx.readObjectTempC(), 0);
 // u8g.drawRFrame(15, 20, 100, 30, 10);     // draws frame with rounded edges
}

void setup(void) 
{
  Serial.begin(9600);
    mlx.begin();  //Receive data from the sensor
}

void loop(void) 
{
  u8g.firstPage();  
  do 
    {
     draw();      
    }
  while( u8g.nextPage() );
  
  delay(1000);  // Delay of 1sec 
}

i have problems combining that function with the code.

What did you try ?

Store the result of mlx.readObjectTempC in a variable.

Does it need to be remembered after a reset? If not, you're done. Else look at the EEPROM.put and EEPROM.get examples

I tried this strings in the void loop, but the problem is that when I pushed the button the temperature is displayed but it is not like memory because it is changing.

if (buttonState == HIGH) {
   
  
    
    u8g.setFont(u8g_font_profont12);
    u8g.drawStr(100,60, mlx.readObjectTempC );
  }

If there is a method to do it without using the EEPROOM it will be nice because i dont need it to be remembered after a reset.

But like sterretje said it will be cool but I'm not very good programming, and I dont know how to define a variable, so if someone could help me with a further explanation it will be cool.

im guessing here

you want to have a live reading of temp but once you press a button you want to save the live reading and only display the saved reading until ???????

yes I want to have a live reading of temp, but When I press a button I want to memorize the current temp in the corner of the screen, while the temp measurement in the center of the screen is still runing.

like this

 static float savedReading;
  static byte oneTime;

  if ((buttonState == HIGH) {
  if (oneTime == 0) {
      savedReading = mlx.readObjectTempC;
      oneTime = 1;
    }
  } else {
    oneTime = 0;
  }

  //do some funky code to display savedReading in the middle of the screen
  //   u8g.setFont(u8g_font_profont12);
  //   u8g.drawStr(80,30, savedReading );//no idea about the numbers

  u8g.setFont(u8g_font_profont12);
  u8g.drawStr(100, 60, mlx.readObjectTempC );//display live temp

}

That's exactly what I want but I have this code error:

exit status 1
no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(int, int, float&)'

What could it be?

Sorry i was wrong, the code is working perfectly

thanks a lot gpop1. :slight_smile: