Serialprintln

I am new my scetch prints “Hello Bryan!” “you did it!” counts seconds,blinks red,yellow.green leds and servo 0 - 180 and sonic.

the problem is Serialprintln prints only once each loop instead of scans radar style.
I try “for”

any suggestions welcome

helptxt.txt (2.82 KB)

Please look at this and follow the instructions for posting code Read this before posting a programming question

it seems like your code needs to do many things and at different times. Of course everything in loop() will be done sequentially. once loop() completes it gets repeated and the sequence repeats. in order to do multiple things seemingly simultaneously, loop() must not be delayed doing one thing while another needs to be done.

one approach is to keep track of the state of things to do and do them only when an appropriate time has elapsed. consider the following code

#define Period1     50
#define Period2    100
#define Period3    150

int           ang   = 0;
int           dAng  = 1;

int           st1   = 0;
int           dist  = 0;

unsigned long msec1 = 0;
unsigned long msec2 = 0;
unsigned long msec3 = 0;

void loop () {

    unsigned long msec = millis();

    // ----------------------------------------
    // period 1 actions
    if (msec - msec1 > Period1) {
        msec1 = msec;

        ang += dAng;
        myservo.write (ang);

        if (0 < dAng && 180 <= ang)
            dAng = -dAng;
        else if (0 > dAng && 0 >= ang)
            dAng = -dAng;
    }

    // ----------------------------------------
    // period 2 actions
    if (msec - msec2 > Period2) {
        msec2 = msec;

        // state1 action
        if (st1)
            digitalWrite (LED, HIGH);

        else                // state2 action
            digitalWrite (LED, LOW);

        st1 = ! st1;      // toggle state
    }

    // ----------------------------------------
    if (msec - msec3 > Period3) {
        msec3 = msec;

        // period 3 actions
        Serial.print   ("Distance: ");
        Serial.println (dist);
    }

    // ----------------------------------------
    // do something that doesn't need to wait
    
    lcd.setCursor(0, 1);
    lcd.print(millis() / 1000);
}