Can I make this section of code neater

Hello all,
I am currently creating a bedroom temperature alarm. I have created a section of code I was just wondering is there anyway to neaten the code or have I made it to wordy.

Basic Program Function.
When bedroom temperature is to high or low this alert system will trigger causing a flashing display on an LCD and active a passive buzzer to sound.

Everything works as intended, just looking for some advice.

  // Alarm code to be activated when room temp is to High or Low.
  lcd1.setCursor(4, 0);
  lcd1.print("ALERT! ");
  lcd1.write(1);
  noTone(PassiveBuzzer1);
  delay(1000);
  lcd1.clear();
  lcd1.setCursor(4, 0);
  lcd1.print("ALERT! ");
  lcd1.write(2);
  tone(PassiveBuzzer1, 200);
  delay(1000); 
  lcd1.clear();

Please post the entire sketch. It can't be "neatened up" safely without knowing the entire context.

This isn't the full program as I have created this separate sketch to test my idea.
So far this is what I have.

#include <LiquidCrystal.h>

const int rs = 2, en = 4, d4 = 7, d5 = 8, d6 = 12, d7 = 13;
LiquidCrystal lcd1(rs, en, d4, d5, d6, d7);

int PassiveBuzzer1 = 3;

byte Bell1[] = {
  B00100,
  B00100,
  B01110,
  B01110,
  B11111,
  B11111,
  B00000,
  B00000
};

byte Bell2[] = {
  B00100,
  B00100,
  B01110,
  B01110,
  B11111,
  B11111,
  B00000,
  B00100
};

void setup() {
  lcd1.begin(16, 2);
  lcd1.createChar(1, Bell1);
  lcd1.createChar(2, Bell2);
  pinMode(3, OUTPUT);
}

void loop() {

  // Alarm code to be activated when room temp is to High or Low.
  lcd1.setCursor(4, 0);
  lcd1.print("ALERT! ");
  lcd1.write(1);
  noTone(PassiveBuzzer1);
  delay(1000);
  lcd1.clear();
  lcd1.setCursor(4, 0);
  lcd1.print("ALERT! ");
  lcd1.write(2);
  tone(PassiveBuzzer1, 200);
  delay(1000); 
  lcd1.clear();
}

You should consider using millis() for timing.

@Deva_Rishi Thanks for advice mate.

I don't think people will want to put actual work into a dummy sketch that isn't the real one. Certainly not me.

I am lost

Order a GPS module. It will tell you your location.

Seriously though, you didn't tell us what you think is wrong with your test sketch. What do you want? Better formatting? Better use of system functions? More efficiency? What?

Some minutae, I would suggest giving the custom characters a name.

You write ALERT, wait one second, clear the screen and immediately write ALERT.

So that doesn't seem to be flashing.

a7

Its my LCD Display it flashes a custom bell char

So, did you test this sketch? What does it actually do, when you run it?

@anon57585045 sketch works as intended just wondered if i could make it less wordy.

Why?

I am still new to all this just wondered if there was any shorter way to write this.

Wouldn't a shorter way be more confusing? Also you are limited to the commands and functions that are available. You can't leave them out.

OIC, custom 1 and 2.

I thought ALERT ought to be flashing, but you do you.

Aside from taking a totally different approach ground up, this is what that code will look like, step by delayed step by step.

a7

I would write more comments.

Also this is not all your code as it makes no sense ie serves no function yet.

It won’t work well with inputs etc unless you get rid of the delays. You could make it work in a very linear way but it won’t be responsive

Would be nicer in a function like
Void alarm(){
Your non blocking code}

@alto777 Thanks for that advice, Will change that i think it will look better.

& @pmagowan yeah mate i will do i always seem to start sketches without comments then add them in later. Possibly a bad habit I need to change.

We're constantly telling people to write test code before writing huge projects. It's a good thing they did this.

Regards the request, I strongly suggest aiming for clarity rather than mere conciseness. That will actually make it more "wordy". But it will be easier to read and maintain.

I agree other than for optimisation we need to know the overall plan. Like if he adds a button it won’t work this way