ultrasonic RGB LED distance code - please advise

I have been working on this code for a while but can't find all of the problems with it.
any help would be appreciated

int ledpinr = 5;
int ledping = 6;
int ledpinb = 7;
int trigPin1 = 8;
int echoPin1 = 9;

int red = 255;
int blue = 255;
int green = 255;

int val;
boolean busy = false;
long duration1, distance1;
void setup() {
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  Serial.begin(9600);
  led_update();

}

void led_update()
{
  //Set PWM on pins 9 10 and 11
  analogWrite(ledpinr, red);
  analogWrite(ledping, green);
  analogWrite(ledpinb, blue);
  //delay(500);
}
void color_morph(int* value, int maxval, int get_brighter)
{
  if (maxval > 255) {
    maxval = 255;
  }
  else if (maxval < 0) {
    maxval = 0;
  }
  for (int i = 0; i < maxval; i++)
  {
    if (get_brighter) {
      if (*value > 0) {
        (*value)--;
      }
    }
    else {
      if (*value < 255) {
        (*value)++;
      }
    }
  }
    led_update();
    delay(5);
     
      
    void loop(){
      
        digitalWrite(trigPin1, LOW);
      
      
      delayMicroseconds(2);

      digitalWrite(trigPin1, HIGH);

      delayMicroseconds(10);

      digitalWrite(trigPin1, LOW);

      duration1 = pulseIn(echoPin1, HIGH);

      distance1 = (duration1 / 2) / 29.1;

      Serial.print(distance1);
      Serial.println("cm");
    }
  }
}

Your void loop does not seem to do anything other than trigger the ultrasonic sensors and serial print the result.

Is that not working?

I'm struggling to make the RGB LED change colour based on proximity. It isn't serial printing either, any ideas?

K_turner:
I'm struggling to make the RGB LED change colour based on proximity. It isn't serial printing either, any ideas?

If you never call those functions, they will never be executed. Review what you have written in "loop".

Paul

The loop() function is nested inside the color_morph() function, which is not allowed.

Start over with the basic ultrasonic ranging example, add function code outside of the loop() and setup() functions, and call the new functions as required.

Example:

void setup() {
...
}
void loop() {
...
color_morph(&x,y,z);
}
void color_morph(int* value, int maxval, int get_brighter) {
...
}