Author Options:

How to add a memory function when I push a button Answered

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 eeprom but i have problems combining that function with the code.

Any help appreciated. Thanks.


#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_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C

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)
    mlx.begin();  //Receive data from the sensor

void loop(void)
  while( u8g.nextPage() );

  delay(1000);  // Delay of 1sec


The forums are retiring in 2021 and are now closed for new topics and comments.

3 years ago

No need for Eeprom storage, all you need is assing the current temp to a variable (if not already done in the sketch) and add that value to the display output in the way you like.
The button would only need to update the display info, or change the value of the variable if yu use a second one for the stored temp.


Answer 3 years ago


He speaks the truth.

EEprom memory is for recall, of a temperature numeric, after a uP power interrupt..