Bluetooth Trigger

Hello guys I have one arduino nano, with bluetooth HC05 and oled display, when receive data from bluetooth I print the data in display.

How I can prevent the display to print +DISC:SUCCESS OK, when connection fails from Android app.

#include <SPI.h>
#include <Wire.h>
#include <SoftwareSerial.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 OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation 

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
#define NUM_SAMPLES 10

 String data="";
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };


//#https://randomnerdtutorials.com/guide-for-oled-display-with-arduino/
/** Display Commands
 display.clearDisplay() – all pixels are off
 display.drawPixel(x,y, color) – plot a pixel in the x,y coordinates
 display.setTextSize(n) – set the font size, supports sizes from 1 to 8
 display.setCursor(x,y) – set the coordinates to start writing text
 display.print(“message”) – print the characters at location x,y
 display.display() – call this method for the changes to make effect
 */

 

int sum = 0;                    // sum of samples taken
unsigned char sample_count = 0; // current sample number
float voltage = 0.0;            // calculated voltage

void setup()
{
  // put your setup code here, to run once:
   Serial.begin(9600);
   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("Display Error"));
    for(;;); // Don't proceed, loop forever
  }
  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(1000);
  //testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
  testdrawbitmap();
  delay(2000);
  display.clearDisplay() ;
}

void testdrawbitmap(void) {
  display.clearDisplay();

  display.drawBitmap(
    (display.width()  - LOGO_WIDTH ) / 2,
    (display.height() - LOGO_HEIGHT) / 2,
    logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
  display.display();
  delay(1000);
}


void loop() 
{
  // put your main code here, to run repeatedly:
  data="";
  display.clearDisplay();
  if(Serial.available() > 0) 
  {
    //while(Serial.available() > 0)
    Serial.print("Incoming_value");        //Print Value of Incoming_value in Serial monitor
    Serial.print("\n");     
    data=Serial.readString();
    if(data==String("+DISC:SUCCESS OK"))
    {
        data="desconetado";
    }
    if(data.equals(String("+DISC:SUCCESS OK")))
    {
        data="desconetado";
    }
    if(data.equalsIgnoreCase(String("+DISC:SUCCESS OK")))
    {
        data="desconetado";
    }
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(10, 20);
    //display.setCursor(0, 10);
    //Display static text
    display.println(data);
    display.display();
    delay(2000);
   data="";
   display.clearDisplay();
  }
  else   if(Serial.available() < 0) 

  {
     display.clearDisplay();
  }
}

I don’t think that it prints when there is no connection, it just stays there. But I might be wrong.

Serial.available will never return a negative number. So below will never clear the display

  else   if(Serial.available() < 0)

  {
     display.clearDisplay();
  }

A simple else will probably be sufficient

  else

  {
     display.clearDisplay();
  }

Note
Don’t use String (capital S) on microcontrollers with small memory. You can encounter runtime problems due to inefficient memory usage.

Hello I solved

One simple tricks

if(Serial.available() > 0) 
  {
    data=Serial.readString();
    if (data.charAt(0) == '#')
    {
      delay(200);
    }
    if(data.charAt(0)=='+'){delay(200); data ="desconected";
    }
   
    if(data.length()>0)
... print