Problema al graficar datos de potenciometro en OLED 128x64

Hola a todos,

Una disculpa de ante mano si me equivoco en algun concepto, soy nuevo en todo este mundo de electronica y arduino.

Necesito graficar datos provenientes de un potenciometro en tiempo real en una pantalla OLED 128x64, tome el codigo de un video de youtube que hace exactamente lo que necesito:


Fuente: :chart_with_upwards_trend: Cómo graficar datos en un display OLED SSD1306 I2C y Arduino fácil - YouTube

Probe el codigo, y funciono exactamente igual en mi pantalla, ahora bien, necesito que la grafica se deje de mostrar cuando oprima un boton, para esto hice un do...while, que mientras el boton no este oprimido, muestre la grafica en pantalla, pero al hacer esto el codigo no corre, la pantalla se queda pegada y no se muestra nada, no enciende de lleno, pero apenas saco el codigo de la grafica del do...while vuelve a funcionar de nuevo, adjunto el codigo

 #include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define IMAGE_HEIGHT   64
#define IMAGE_WIDTH    128
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


int menuTemp, menuTempIni;
int botonInicio = 2;
int botonMenu = 3;
int botonAbajo = 4;
int botonEnter = 5;
int anteriorMillis = 0;
int tiempo = 0;
float valorAnalogico = 0;
float voltaje = 0;
float graficaVoltaje = 0;

int x[128]; //buffer de la grafica
int y[128]; //buffer secundario de la grafica
static const unsigned char PROGMEM imagen[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x41, 0x14, 0x30, 0x30, 0x83, 0x04, 0x80, 0xC0,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x41, 0x10, 0x08, 0x88, 0x84, 0x04, 0x40, 0x20,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x41, 0x10, 0x80, 0x80, 0x88, 0x44, 0x22, 0x00,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x42, 0x10, 0x84, 0x80, 0x88, 0x44, 0x22, 0x10,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x78, 0x10, 0xFC, 0x40, 0x88, 0x04, 0x23, 0xF0,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x10, 0x88, 0x04, 0x22, 0x00,
  0x3F, 0xFF, 0xFE, 0x0F, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x00, 0x88, 0x04, 0x22, 0x00,
  0x3F, 0xFF, 0xFC, 0x07, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x84, 0x88, 0x44, 0x22, 0x00,
  0x3F, 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x40, 0x88, 0x84, 0x04, 0x21, 0x00,
  0x3F, 0xFF, 0xE0, 0x00, 0x7F, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x30, 0x30, 0x83, 0x04, 0x20, 0xC0,
  0x3F, 0xFF, 0x80, 0x20, 0x1F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xFE, 0x00, 0x30, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xFC, 0x04, 0x7C, 0x03, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x7F, 0x04, 0x0F, 0x0F, 0xF0,
  0x3F, 0xF0, 0x08, 0x7F, 0x00, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x04, 0x08, 0x0C, 0x08, 0x40, 0x80,
  0x3F, 0xE0, 0x38, 0x7F, 0xC0, 0x3F, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x0C, 0x08, 0x00, 0x80,
  0x3F, 0x80, 0xC0, 0x3F, 0xF0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x82, 0x08, 0x0A, 0x08, 0x20, 0x80,
  0x3E, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x02, 0x08, 0x20, 0x80,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x40, 0x08, 0x12, 0x08, 0x40, 0x80,
  0x38, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x08, 0x10, 0x0F, 0x80, 0x80,
  0x38, 0x00, 0xF1, 0xFF, 0xC0, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x04, 0x08, 0x01, 0x08, 0x40, 0x80,
  0x38, 0x02, 0x11, 0xE0, 0x38, 0xF1, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x08, 0x21, 0x08, 0x00, 0x80,
  0x3F, 0xC0, 0x01, 0xC0, 0x18, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x02, 0x08, 0x3F, 0x08, 0x20, 0x80,
  0x3F, 0xC0, 0x01, 0xC0, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x20, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x01, 0x80, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x84, 0x08, 0x40, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x81, 0x87, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x08, 0x40, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x81, 0x87, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x81, 0x87, 0x88, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x81, 0x87, 0x88, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x01, 0x80, 0x08, 0xFF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0x3F, 0xC0, 0x01, 0xC0, 0x18, 0xFF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0x3F, 0xC0, 0x01, 0xF0, 0x18, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC2, 0x31, 0xF0, 0x78, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC0, 0x00, 0x00, 0xF0, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00, 0x60, 0x80,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x9F, 0xC0, 0x60, 0xC0, 0x64, 0x30,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0xC0, 0x60, 0x00, 0x60, 0x70, 0x18,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x70, 0x18,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x08,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0xE0, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x20, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x40, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0xC0, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xC0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xC0, 0x06, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x08,
  0x1C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0x80, 0x06, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x18,
  0x0C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0x80, 0x06, 0x03, 0x81, 0x80, 0x60, 0xC0, 0xE0, 0x70, 0x10,
  0x04, 0x7F, 0xF1, 0xFF, 0xFF, 0x86, 0x00, 0x03, 0xF9, 0x81, 0x80, 0x60, 0x60, 0x38, 0x40, 0x20,
  0x00, 0x7F, 0xF1, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x80,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};



void setup() {

  pinMode(botonInicio, INPUT);
  pinMode(botonMenu, INPUT);
  pinMode(botonAbajo, INPUT);
  pinMode(botonEnter, INPUT);

  // initialize serial port
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(WHITE);
  display.setTextSize(1);  // ajusta el tamaño de texto en el minimo valor

  for (int i = 0; i < 1; i++) {
    display.clearDisplay();  // limpia el buffer del display
    display.drawBitmap(0, 0, imagen, 128, 64, 1); // despliega imagen
    display.display(); // muestra la informacion del buffer en la pantalla
    delay(3000); //pausa
    display.display(); //muestra el buffer limpio
  }
  //llenamos las matrices con un valor fuera del rango de medicion >1023
  for (int i = 127; i >= 0; i--) {
    x[i] = 9999;
  }
  for (int i = 127; i >= 0; i--) {
    y[i] = 9999;
  }
}

void loop() {


  // INICIO - PANTALLA DE INICIO
  while (digitalRead(botonMenu) == 1 && menuTemp != 6 && menuTemp != 3)
  {
    header2();
    display.setCursor(35, 10);
    display.setTextSize(1);
    display.print("Bienvenido,");
    display.setTextSize(2);
    display.setCursor(  25,   26);
    display.print ("INICIAR");
    display.setTextSize(1);
    display.setCursor(  35,  48);
    display.print ("15 de Abril");
    refresh();
  }
  // FIN - PANTALLA DE INICIO

  menuTemp = 6;

  // INICIO - MENU PRINCIPAL
  if (digitalRead(botonMenu) == 0 || menuTemp == 6 && digitalRead(botonAbajo) == 1 || menuTemp == 3) {
    do
    {
      header();
      display.setCursor(0, 11);  display.print (">TOMAR PRESION");
      display.setCursor(0, 20);  display.print (" REGISTRO DE PRESION");
      //  display.setCursor(0,29);  display.print (" DATA RECORD");
      display.setCursor(0, 47);  display.print (" AYUDA");
      display.setCursor(0, 56);  display.print (" ACERCA DE");
      refresh();

    } while (digitalRead(botonAbajo) == 1 && digitalRead(botonEnter) == 1);
    menuTemp = 0;
  }


  if (digitalRead(botonAbajo) == 0 && menuTemp == 0)
  {
    delay(250);
    do {
      header();
      display.setCursor(0, 11);  display.print (" TOMAR PRESION");
      display.setCursor(0, 20);  display.print (">REGISTRO DE PRESION");
      //  display.setCursor(0,29);  display.print (" DATA RECORD");

      display.setCursor(0, 47);  display.print (" AYUDA");
      display.setCursor(0, 56);  display.print (" ACERCA DE");
      refresh();
    } while (digitalRead(botonAbajo) == 1 && digitalRead(botonEnter) == 1);
    menuTemp = 1;
  }


  if (digitalRead(botonAbajo) == 0 && menuTemp == 1)
  {
    delay(250);
    do {
      header();
      display.setCursor(0, 11);  display.print (" TOMAR PRESION");
      display.setCursor(0, 20);  display.print (" REGISTRO DE PRESION");
      //  display.setCursor(0,29);  display.print (" DATA RECORD");

      display.setCursor(0, 47);  display.print (">AYUDA");
      display.setCursor(0, 56);  display.print (" ACERCA DE");
      refresh();
    } while (digitalRead(botonAbajo) == 1 && digitalRead(botonEnter) == 1);
    menuTemp = 2;
  }


  if (digitalRead(botonAbajo) == 0 && menuTemp == 2)
  {
    delay(250);
    do {
      header();
      display.setCursor(0, 11);  display.print (" TOMAR PRESION");
      display.setCursor(0, 20);  display.print (" REGISTRO DE PRESION");
      //  display.setCursor(0,29);  display.print (" DATA RECORD");
      display.setCursor(0, 47);  display.print (" AYUDA");
      display.setCursor(0, 56);  display.print (">ACERCA DE");
      refresh();
    } while (digitalRead(botonAbajo) == 1 && digitalRead(botonEnter) == 1);
    menuTemp = 3;
  }
  //  // FIN - MENU PRINCIPAL

  //
  //  // INICIO - TOMAR PRESION
  if (digitalRead(botonEnter) == 0 && menuTemp == 0)
  {
    delay(250);
    do {
      header();
      display.setCursor(0, 11);  display.print ("--- TOMAR PRESION ---");
      display.setCursor(0, 20);  display.print (">INICIAR");
      display.setCursor(0, 29);  display.print (" PROBAR SISTEMAS");
      display.setCursor(0, 56);  display.print (" ATRAS");
      refresh();
              delay(100);

    } while (digitalRead(botonAbajo) == 1 && digitalRead(botonEnter) == 1);
    menuTemp = 4;

  }


  if (digitalRead(botonAbajo) == 0 && menuTemp == 4)
  {
    delay(250);
    do {
      header();
      display.setCursor(0, 11);  display.print ("--- TOMAR PRESION ---");
      display.setCursor(0, 20);  display.print (" INICIAR");
      display.setCursor(0, 29);  display.print (">PROBAR SISTEMAS");
      display.setCursor(0, 56);  display.print (" ATRAS");
      refresh();
    } while (digitalRead(botonAbajo) == 1 && digitalRead(botonEnter) == 1);
    menuTemp = 5;
  }


  if (digitalRead(botonAbajo) == 0 && menuTemp == 5)
  {
    delay(250);
    do {
      header();
      display.setCursor(0, 11);  display.print ("--- TOMAR PRESION ---");
      display.setCursor(0, 20);  display.print (" INICIAR");
      display.setCursor(0, 29);  display.print (" PROBAR SISTEMAS");
      display.setCursor(0, 56);  display.print ("<ATRAS");
      refresh();
    } while (digitalRead(botonAbajo) == 1 && digitalRead(botonEnter) == 1);
    menuTemp = 6;
    delay(250);
  }


  if (digitalRead(botonEnter) == 0 && menuTemp == 4)
  {
    do {
      display.clearDisplay(); //limpia el buffer del display

      //dibuja escala
      display.setCursor(0, 0);
      display.print(F("200"));
      display.setCursor(0, 11);
      display.print(F("160"));
      display.setCursor(0, 22);
      display.print(F("120"));
      display.setCursor(0, 32);
      display.print(F("80"));
      display.setCursor(0, 43);
      display.print(F("40"));

      display.drawLine(0, 53, 0, 64, WHITE);
      display.drawLine(127, 53, 127, 64, WHITE);

      display.drawLine(20, 0, 25, 0, WHITE);
      display.drawLine(20, 11, 25, 11, WHITE);
      display.drawLine(20, 22, 25, 22, WHITE);
      display.drawLine(20, 32, 25, 32, WHITE);
      display.drawLine(20, 43, 25, 43, WHITE);
      //dibuja eje X y Y
      display.drawLine(0, 53, 127, 53, WHITE);
      display.drawLine(25, 53, 25, 0, WHITE);

      valorAnalogico = analogRead(A0); //lee el valor analogico del pin A0
      voltaje = (valorAnalogico * 5) / 1024; //calcula el valor en voltaje
      graficaVoltaje = map(valorAnalogico, 0, 1023, 53, 0); //escala el valor analogico a un pixel imprimible en pantalla

      x[127] = graficaVoltaje; //asigna el valor escalado a el ultimo dato de la matriz

          for(int i=127;i>=25;i--){
//              display.drawPixel(i, x[i], WHITE); //dibuja punto a punto el contenido de x
//              y[i-1]=x[i]; //guarda la informacion desplazada una posicion temporalmente en y
//            }
      //imprime el voltaje en texto
      display.setCursor(5, 57);
    
      display.print(voltaje);
      display.print(F(" mmHg    "));

      //imprime el tiempo que se tarda en tomar y mostrar cada dato
      tiempo = millis() - anteriorMillis;
      display.print(tiempo);
      anteriorMillis = millis();
      display.print(F(" ms"));

      display.display(); //despliega la informacion del buffer en la pantalla

      //delay(60); //pausa opcional

//          for(int i=127;i>=0;i--){
//            x[i]=y[i]; //envia los datos desplazados de vuelta a la variable x
//          }

    } while (digitalRead(botonMenu) == 1);
    menuTemp = 3;
    delay(250);

  }
void header()
{
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(55, 0);  display.print("MENU");
  display.drawLine (0, 9, 128, 9, WHITE);
  display.drawLine (0, 0, 0, 9, WHITE);
  display.drawLine (127, 9, 127,0, WHITE);

}

void header2()
{
  display.setTextSize(1);
  display.setTextColor(WHITE);
  //  display.setCursor(45, 0);  display.print("UNAB");
  display.drawRect(0, 0, 128, 64 , WHITE);
  display.drawRect(1, 1, 126, 62 , WHITE);
  display.drawRect(2, 2, 124, 60 , WHITE);


}

void refresh()
{
  display.display();
  delay(00);
  display.clearDisplay();
}

Las partes que estan en comentario (los dos ciclos for), las tengo asi porque hice una pequeña depuracion y me di cuenta que esas lineas son las que no funcionan dentro del ciclo do...while, pero sin esa parte del codigo solo se muestra en pantalla el eje X y el eje Y, los datos no se muestran:
https://photos.app.goo.gl/5DTZyNFy6vSwJb8x5
Fuente: propia

Si vuelvo a activar las partes comentadas, al momento de subir el codigo todo deja de funcionar:
https://photos.app.goo.gl/cD7Jou6ntXJZofPu6
Fuente: propia

Si me pueden dar una mano lo agradezco, saludos.

Primero que nada, el código a medias no sirve, súbelo completo.
Las razones por las que con tu modificación no se muestra el gráfico están en la parte del código que no vemos.

El lazo que has hecho haría que se muestre el gráfico (si funcionase, claro) mientras no tengas el botón pulsado pero para ocultarlo tienes que mantenerlo pulsado, imagino que pensaste en un interruptor y no un pulsador, sino cuando lo sueltas inmediatamente aparece el gráfico.

Tienes que usar una variable que cambie de true a false y viceversa, cada vez que pulsas el botón, luego según el valor de esa variable muestras o no el gráfico.

Saludos

Hola,

Ya puse todo el codigo y puse unos videos donde trato de mostrar el problema de mejor manera.

Gracias por tu mensaje.

Probá descomentando

//delay(60); //pausa opcional

Creo que el problema pasa por la velocidad de actualización de la pantalla
Antes dibujaba el gráfico y ejecutaba todo el resto del código, así que estaba "un ratito" hasta que se volvía dibujar. Ahora dentro del do-while se dibuja y borra continuamente sin pausa.

Descomento lo que mencionas, y descomento los dos ciclos for que estan dentro del do-while y la pantalla no enciende, no corre nada del codigo, cuando vuelvo a comentar los dos ciclos for el programa corre normal, pero sin los ciclos for no se muestran los datos de la grafica. Estuve depurando el codigo, y me di cuenta que el problema radica cuando pongo ciclos do-while en cualquier parte, deja de funcionar los for, por ejemplo, de esta manera el codigo hace exactamente lo que le pido:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define IMAGE_HEIGHT   64
#define IMAGE_WIDTH    128
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


int menuTemp, menuTempIni;
int botonInicio = 2;
int botonMenu = 3;
int botonAbajo = 4;
int botonEnter = 5;
int anteriorMillis = 0;
int tiempo = 0;
float valorAnalogico = 0;
float voltaje = 0;
float graficaVoltaje = 0;

int x[128]; //buffer de la grafica
int y[128]; //buffer secundario de la grafica
static const unsigned char PROGMEM imagen[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x41, 0x14, 0x30, 0x30, 0x83, 0x04, 0x80, 0xC0,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x41, 0x10, 0x08, 0x88, 0x84, 0x04, 0x40, 0x20,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x41, 0x10, 0x80, 0x80, 0x88, 0x44, 0x22, 0x00,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x42, 0x10, 0x84, 0x80, 0x88, 0x44, 0x22, 0x10,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x78, 0x10, 0xFC, 0x40, 0x88, 0x04, 0x23, 0xF0,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x10, 0x88, 0x04, 0x22, 0x00,
  0x3F, 0xFF, 0xFE, 0x0F, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x00, 0x88, 0x04, 0x22, 0x00,
  0x3F, 0xFF, 0xFC, 0x07, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x84, 0x88, 0x44, 0x22, 0x00,
  0x3F, 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x40, 0x88, 0x84, 0x04, 0x21, 0x00,
  0x3F, 0xFF, 0xE0, 0x00, 0x7F, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x30, 0x30, 0x83, 0x04, 0x20, 0xC0,
  0x3F, 0xFF, 0x80, 0x20, 0x1F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xFE, 0x00, 0x30, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xFC, 0x04, 0x7C, 0x03, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x7F, 0x04, 0x0F, 0x0F, 0xF0,
  0x3F, 0xF0, 0x08, 0x7F, 0x00, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x04, 0x08, 0x0C, 0x08, 0x40, 0x80,
  0x3F, 0xE0, 0x38, 0x7F, 0xC0, 0x3F, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x0C, 0x08, 0x00, 0x80,
  0x3F, 0x80, 0xC0, 0x3F, 0xF0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x82, 0x08, 0x0A, 0x08, 0x20, 0x80,
  0x3E, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x02, 0x08, 0x20, 0x80,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x40, 0x08, 0x12, 0x08, 0x40, 0x80,
  0x38, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x08, 0x10, 0x0F, 0x80, 0x80,
  0x38, 0x00, 0xF1, 0xFF, 0xC0, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x04, 0x08, 0x01, 0x08, 0x40, 0x80,
  0x38, 0x02, 0x11, 0xE0, 0x38, 0xF1, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x08, 0x21, 0x08, 0x00, 0x80,
  0x3F, 0xC0, 0x01, 0xC0, 0x18, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x02, 0x08, 0x3F, 0x08, 0x20, 0x80,
  0x3F, 0xC0, 0x01, 0xC0, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x20, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x01, 0x80, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x84, 0x08, 0x40, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x81, 0x87, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x08, 0x40, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x81, 0x87, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x81, 0x87, 0x88, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x81, 0x87, 0x88, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x01, 0x80, 0x08, 0xFF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0x3F, 0xC0, 0x01, 0xC0, 0x18, 0xFF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0x3F, 0xC0, 0x01, 0xF0, 0x18, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC2, 0x31, 0xF0, 0x78, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC0, 0x00, 0x00, 0xF0, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00, 0x60, 0x80,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x9F, 0xC0, 0x60, 0xC0, 0x64, 0x30,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0xC0, 0x60, 0x00, 0x60, 0x70, 0x18,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x70, 0x18,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x08,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0xE0, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x20, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x40, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0xC0, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xC0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xC0, 0x06, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x08,
  0x1C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0x80, 0x06, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x18,
  0x0C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0x80, 0x06, 0x03, 0x81, 0x80, 0x60, 0xC0, 0xE0, 0x70, 0x10,
  0x04, 0x7F, 0xF1, 0xFF, 0xFF, 0x86, 0x00, 0x03, 0xF9, 0x81, 0x80, 0x60, 0x60, 0x38, 0x40, 0x20,
  0x00, 0x7F, 0xF1, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x80,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};



void setup() {

  pinMode(botonInicio, INPUT);
  pinMode(botonMenu, INPUT);
  pinMode(botonAbajo, INPUT);
  pinMode(botonEnter, INPUT);

  // initialize serial port
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(WHITE);
  display.setTextSize(1);  // ajusta el tamaño de texto en el minimo valor

  for (int i = 0; i < 1; i++) {
    display.clearDisplay();  // limpia el buffer del display
    display.drawBitmap(0, 0, imagen, 128, 64, 1); // despliega imagen
    display.display(); // muestra la informacion del buffer en la pantalla
    delay(3000); //pausa
    display.display(); //muestra el buffer limpio
  }
  //llenamos las matrices con un valor fuera del rango de medicion >1023
  for (int i = 127; i >= 0; i--) {
    x[i] = 9999;
  }
  for (int i = 127; i >= 0; i--) {
    y[i] = 9999;
  }
}

void loop() {
    display.clearDisplay(); //limpia el buffer del display
    
    //dibuja escala
    display.setCursor(0, 0); 
    display.print(F("5V")); 
    display.setCursor(0, 11);   
    display.print(F("4V"));
    display.setCursor(0, 22); 
    display.print(F("3V"));
    display.setCursor(0, 32);  
    display.print(F("2V"));      
    display.setCursor(0, 43); 
    display.print(F("1V")); 
  
    display.drawLine(15, 0, 25, 0, WHITE);
    display.drawLine(15, 11, 25, 11, WHITE);
    display.drawLine(15, 22, 25, 22, WHITE);
    display.drawLine(15, 32, 25, 32, WHITE);
    display.drawLine(15, 43, 25, 43, WHITE);
    //dibuja eje X y Y 
    display.drawLine(0, 53, 127, 53, WHITE);
    display.drawLine(25, 53, 25, 0, WHITE);
   
    valorAnalogico = analogRead(A0); //lee el valor analogico del pin A0
    voltaje=(valorAnalogico*5)/1024; //calcula el valor en voltaje
    graficaVoltaje=map(valorAnalogico,0,1023,53,0); //escala el valor analogico a un pixel imprimible en pantalla
  
    x[127]=graficaVoltaje; //asigna el valor escalado a el ultimo dato de la matriz
    
    for(int i=127;i>=25;i--){ 
        display.drawPixel(i, x[i], WHITE); //dibuja punto a punto el contenido de x
        y[i-1]=x[i]; //guarda la informacion desplazada una posicion temporalmente en y
      }
    //imprime el voltaje en texto  
    display.setCursor(25, 57); 
    display.print(voltaje);
    display.print(F(" v    "));
  
    //imprime el tiempo que se tarda en tomar y mostrar cada dato
    tiempo = millis()-anteriorMillis;
    display.print(tiempo);
    anteriorMillis = millis();
    display.print(F(" ms"));
      
    display.display(); //despliega la informacion del buffer en la pantalla
    
    //delay(60); //pausa opcional
  
    for(int i=127;i>=0;i--){
      x[i]=y[i]; //envia los datos desplazados de vuelta a la variable x
    }
}

Apenas pongo un ciclo do-while todo el codigo deja de funcionar y la pantalla se queda congelada.

Acabo de poner un ciclo do-while sencillo con el codigo unicamente de la grafica y funciona, creo que el problema esta en el codigo largo, voy a revisarlo de nuevo a ver si encuentro algun error.

Si, tenés que reorganizarlo, está muy "enredado" tu menú.

Hola, lleve el codigo a la version mas minima posible y obtuve esto:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define IMAGE_HEIGHT   64
#define IMAGE_WIDTH    128
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


int menuTemp, menuTempIni;
int botonInicio = 2;
int botonMenu = 3;
int botonAbajo = 4;
int botonEnter = 5;
int anteriorMillis = 0;
int tiempo = 0;
float valorAnalogico = 0;
float voltaje = 0;
float graficaVoltaje = 0;

int x[128]; //buffer de la grafica
int y[128]; //buffer secundario de la grafica
static const unsigned char PROGMEM imagen[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x41, 0x14, 0x30, 0x30, 0x83, 0x04, 0x80, 0xC0,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x41, 0x10, 0x08, 0x88, 0x84, 0x04, 0x40, 0x20,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x41, 0x10, 0x80, 0x80, 0x88, 0x44, 0x22, 0x00,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x42, 0x10, 0x84, 0x80, 0x88, 0x44, 0x22, 0x10,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x78, 0x10, 0xFC, 0x40, 0x88, 0x04, 0x23, 0xF0,
  0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x10, 0x88, 0x04, 0x22, 0x00,
  0x3F, 0xFF, 0xFE, 0x0F, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x00, 0x88, 0x04, 0x22, 0x00,
  0x3F, 0xFF, 0xFC, 0x07, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x80, 0x84, 0x88, 0x44, 0x22, 0x00,
  0x3F, 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x40, 0x88, 0x84, 0x04, 0x21, 0x00,
  0x3F, 0xFF, 0xE0, 0x00, 0x7F, 0xFF, 0xE0, 0x00, 0x40, 0x10, 0x30, 0x30, 0x83, 0x04, 0x20, 0xC0,
  0x3F, 0xFF, 0x80, 0x20, 0x1F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xFE, 0x00, 0x30, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xFC, 0x04, 0x7C, 0x03, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x7F, 0x04, 0x0F, 0x0F, 0xF0,
  0x3F, 0xF0, 0x08, 0x7F, 0x00, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x04, 0x08, 0x0C, 0x08, 0x40, 0x80,
  0x3F, 0xE0, 0x38, 0x7F, 0xC0, 0x3F, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x0C, 0x08, 0x00, 0x80,
  0x3F, 0x80, 0xC0, 0x3F, 0xF0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x82, 0x08, 0x0A, 0x08, 0x20, 0x80,
  0x3E, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x02, 0x08, 0x20, 0x80,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x40, 0x08, 0x12, 0x08, 0x40, 0x80,
  0x38, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x08, 0x10, 0x0F, 0x80, 0x80,
  0x38, 0x00, 0xF1, 0xFF, 0xC0, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x04, 0x08, 0x01, 0x08, 0x40, 0x80,
  0x38, 0x02, 0x11, 0xE0, 0x38, 0xF1, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x08, 0x21, 0x08, 0x00, 0x80,
  0x3F, 0xC0, 0x01, 0xC0, 0x18, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x02, 0x08, 0x3F, 0x08, 0x20, 0x80,
  0x3F, 0xC0, 0x01, 0xC0, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x08, 0x20, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x01, 0x80, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x84, 0x08, 0x40, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x81, 0x87, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x30, 0x08, 0x40, 0x88, 0x20, 0x80,
  0x3F, 0xC0, 0x81, 0x87, 0x08, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x81, 0x87, 0x88, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x81, 0x87, 0x88, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC0, 0x01, 0x80, 0x08, 0xFF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0x3F, 0xC0, 0x01, 0xC0, 0x18, 0xFF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0x3F, 0xC0, 0x01, 0xF0, 0x18, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC2, 0x31, 0xF0, 0x78, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC3, 0xF1, 0xFF, 0xF8, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3F, 0xC0, 0x00, 0x00, 0xF0, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00, 0x60, 0x80,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x9F, 0xC0, 0x60, 0xC0, 0x64, 0x30,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0xC0, 0x60, 0x00, 0x60, 0x70, 0x18,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x70, 0x18,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x08,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0xE0, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x00, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x20, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x40, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xE0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0xC0, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xC0, 0x0E, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x0C,
  0x3C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0xC0, 0x06, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x08,
  0x1C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0x80, 0x06, 0x01, 0x81, 0x80, 0x60, 0x80, 0x60, 0x60, 0x18,
  0x0C, 0x7F, 0xF1, 0xFF, 0xFF, 0x87, 0x80, 0x06, 0x03, 0x81, 0x80, 0x60, 0xC0, 0xE0, 0x70, 0x10,
  0x04, 0x7F, 0xF1, 0xFF, 0xFF, 0x86, 0x00, 0x03, 0xF9, 0x81, 0x80, 0x60, 0x60, 0x38, 0x40, 0x20,
  0x00, 0x7F, 0xF1, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x80,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};



void setup() {

  pinMode(botonInicio, INPUT);
  pinMode(botonMenu, INPUT);
  pinMode(botonAbajo, INPUT);
  pinMode(botonEnter, INPUT);

  // initialize serial port
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(WHITE);
  display.setTextSize(1);  // ajusta el tamaño de texto en el minimo valor

  for (int i = 0; i < 1; i++) {
    display.clearDisplay();  // limpia el buffer del display
    display.drawBitmap(0, 0, imagen, 128, 64, 1); // despliega imagen
    display.display(); // muestra la informacion del buffer en la pantalla
    delay(3000); //pausa
    display.display(); //muestra el buffer limpio
  }
  //llenamos las matrices con un valor fuera del rango de medicion >1023
  for (int i = 127; i >= 0; i--) {
    x[i] = 9999;
  }
  for (int i = 127; i >= 0; i--) {
    y[i] = 9999;
  }
}

void loop() {

  // INICIO - TOMAR PRESION
  do {
    display.clearDisplay();
    display.setCursor(0, 11);  display.print ("--- TOMAR PRESION ---");
    display.setCursor(0, 20);  display.print (">INICIAR");
    display.setCursor(0, 29);  display.print (" PROBAR SISTEMAS");
    display.setCursor(0, 56);  display.print (" ATRAS");
    display.display();
    delay(100);
    menuTemp = 4;
  } while (digitalRead(botonEnter) == 1);

  
  if (digitalRead(botonEnter) == 0 && menuTemp == 4)
  {
    do {
      display.clearDisplay(); //limpia el buffer del display

      //dibuja escala
      display.setCursor(0, 0);
      display.print(F("200"));
      display.setCursor(0, 11);
      display.print(F("160"));
      display.setCursor(0, 22);
      display.print(F("120"));
      display.setCursor(0, 32);
      display.print(F("80"));
      display.setCursor(0, 43);
      display.print(F("40"));

      display.drawLine(0, 53, 0, 64, WHITE);
      display.drawLine(127, 53, 127, 64, WHITE);

      display.drawLine(20, 0, 25, 0, WHITE);
      display.drawLine(20, 11, 25, 11, WHITE);
      display.drawLine(20, 22, 25, 22, WHITE);
      display.drawLine(20, 32, 25, 32, WHITE);
      display.drawLine(20, 43, 25, 43, WHITE);
      //dibuja eje X y Y
      display.drawLine(0, 53, 127, 53, WHITE);
      display.drawLine(25, 53, 25, 0, WHITE);

      valorAnalogico = analogRead(A0); //lee el valor analogico del pin A0
      voltaje = (valorAnalogico * 5) / 1024; //calcula el valor en voltaje
      graficaVoltaje = map(valorAnalogico, 0, 1023, 53, 0); //escala el valor analogico a un pixel imprimible en pantalla

      x[127] = graficaVoltaje; //asigna el valor escalado a el ultimo dato de la matriz

      for (int i = 127; i >= 25; i--) {
        display.drawPixel(i, x[i], WHITE); //dibuja punto a punto el contenido de x
        y[i - 1] = x[i]; //guarda la informacion desplazada una posicion temporalmente en y
      }
      //imprime el voltaje en texto
      display.setCursor(5, 57);

      display.print(voltaje);
      display.print(F(" mmHg    "));

      //imprime el tiempo que se tarda en tomar y mostrar cada dato
      tiempo = millis() - anteriorMillis;
      display.print(tiempo);
      anteriorMillis = millis();
      display.print(F(" ms"));

      display.display(); //despliega la informacion del buffer en la pantalla

//      delay(60); //pausa opcional

      for (int i = 127; i >= 0; i--) {
        x[i] = y[i]; //envia los datos desplazados de vuelta a la variable x
      }

    } while (digitalRead(botonMenu) == 1);
    delay(250);

  }
  // FIN - TOMAR PRESION
}

El loop empieza con un do-while el cual, si lo mantengo en el codigo, no corre nada, pantalla en negro, pero, si quito ese do-while el codigo corre perfectamente, osea, esto es lo que me genera conflicto:

  do {
    display.clearDisplay();
    display.setCursor(0, 11);  display.print ("--- TOMAR PRESION ---");
    display.setCursor(0, 20);  display.print (">INICIAR");
    display.setCursor(0, 29);  display.print (" PROBAR SISTEMAS");
    display.setCursor(0, 56);  display.print (" ATRAS");
    display.display();
    delay(100);
    menuTemp = 4;
  } while (digitalRead(botonEnter) == 1);

Ahora bien, he intentado hacer variaciones de ese menu, haciendo un while o cambiando el contenido del blucle do-while y no veo el error :(.

Gracias de antemano.

Para mi lo estás encarando mal, tendrías que hacer una máquina de estados.
En Documentación hay un tutorial.

1 Like

Hola,

Acabo de encontrar una solución, resulta que, al descomentar los dos ciclos for, debo poner en todas las sentencias display.print una F, de esta manera:

Antes:
display.print(" ms");

Despues:
display.print(F(" ms"));

Hice esto con todos los display.print y ahora el codigo corre sin problema y me muestra los datos del potenciometro en tiempo real en la grafica, y el menu funciona correctamente, no entiendo porque, pero bueno, si sabes alguna razon, quedo atento,

Gracias.

Se estaría quedando muy corto de memoria.
Ya 1K se consumen los 2 arrays.
Al usar la macro F() esas cadenas no se copian a RAM, o sea que liberaste memoria.
Creo que esa es la explicación más lógica.

Ya hemos visto que muchas librerías OLED tienen un consumo excesivo de Flash y que dejan al Arduino UNO o NANO en condiciones límites.
Hay una librería que maneja mejor los recursos.
El tema se debatió hace un par de meses. Cuestión de buscarlo.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.