where to put serial display code?

I'm newbie...don't have lots of experience with Arduino.

I'm running a sketch using an SR04 ultrasonic transducer, taken from the Drone Bot Workshop. It works well and displays values on the computer monitor.

I have the example codes for a serial LCD (which I've used a lot with PIC MCUS) and wired the LCD accordingly and defined the pins in the sketch. But when I insert the code, the monitor no longer displays values. I don't get anything on the LCD either...not sure if that's a code or a hardware problem.

The program works with data sent to computer monitor if lines 73-76 are commented out, as shown in the attached sketch. Uncommented, nothing works.

Attached is the code. If someone can verify the components of the code are in the right place.

USonicTHDisplayFE.ino (2.59 KB)

The code lines get run in order from top to bottom. Where to put the code isn't some esoteric magic thing. You put them in the set of instructions at the point where you want the thing to happen.

Please post your program here using code tags when you do.

Your code does not even compile....

  if (Serial.available()) [b][color=red]{[/color][/b] <-- where does this bracket get closed?

     delay(100);
    lcd.clear();
    while (Serial.available() > 0) {
      lcd.write(Serial.read()); //  Send results to Serial Monitor
    }

a delay(100); is a very poor way to handle the serial incoming data...

I took the LCD code from a sample sketch and put the code snippets where I thought they should be.

I tried just the LCD sketch alone and it didn't work.

So I got a different sketch that was simpler and made more sense to me. I think I had the wrong code in the first place!!! This one doesn't have those "If serial available" lines

All working now: data to LCD and data also to the monitor.

Attached is updated file.

USonicTHDisplayFE.ino (2.58 KB)

See #2

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R