Programming problem with simplifying code using ultrasonic ping library

Desperate to make this code simpler, everything works but I am using 12 sensors and 12 led's so it is cumbersome. Please help.

//Ultrasonic Led brightness project
#include <Ultrasonic.h>
Ultrasonic ultrasonic1 (22,23);
Ultrasonic ultrasonic2 (24,24);
int pwmLed1 = 2;
int pwmLed2 = 3;

// start of the low flicker variables
static int flicker_low_min1 = 50;
static int flicker_low_max2 = 60;

// end of the low flicker variables
static int flicker_low_min3 = 61;
static int flicker_low_max4 = 71;

// start of the middle flicker variables
static int flicker_mid_min1 = 120;
static int flicker_mid_max2 = 130;

// end of the middle flicker variables
static int flicker_mid_min3 = 140;
static int flicker_mid_max4 = 150;

// start of the high flicker variables
static int flicker_high_min1 = 200;
static int flicker_high_max2 = 240;

// end value of the high flicker variables
static int flicker_high_min3 = 230;
static int flicker_high_max4 = 256;

// delay between each low-high-low cycle
// low->high |flicker_hold| high->low
static int flicker_hold_min = 40; // milliseconds
static int flicker_hold_max = 80; // milliseconds

// delay after each low-high-low cycle
// low->high->low |flicker_pause| low->high...
static int flicker_pause_min = 5; // milliseconds
static int flicker_pause_max = 10; // milliseconds

// delay low to high and high to low cycle
static int flicker_speed_min = 900; // microseconds
static int flicker_speed_max = 1000; // microseconds

void setup() {
Serial.begin(9600);
//for (int i = 0; i<12;i++) {
//pinMode(pwmLed*, OUTPUT);*

  • //}*

  • pinMode (pwmLed1, OUTPUT);*

  • pinMode (pwmLed2, OUTPUT);*
    }
    //low flicker start, stop, random
    int flicker_random_low_start = 0;
    int flicker_random_low_end = 0;
    int flicker_random_low = 0;
    //mid flicker start, stop, random
    int flicker_random_mid_start = 0;
    int flicker_random_mid_end = 0;
    int flicker_random_mid = 0;
    //high flicker start, stop, random
    int flicker_random_high_start = 0;
    int flicker_random_high_end = 0;
    int flicker_random_high = 0;
    // flicker random speed
    int flicker_random_speed_start = 0;
    int flicker_random_speed_end = 0;
    void loop()
    {

  • int brightness1, brightness2;*

  • int distance1,distance2;*

  • //low flicker algorithm*

  • flicker_random_low_start = random(flicker_low_min1, flicker_low_max2);*

  • flicker_random_low_end = random(flicker_low_min1, flicker_low_max2);*

  • // random time for low*

  • flicker_random_low = random(flicker_low_min3, flicker_low_max4);*

  • //---------*

  • //mid flicker algorithm*

  • flicker_random_mid_start = random(flicker_mid_min1, flicker_mid_max2);*

  • flicker_random_mid_end = random(flicker_mid_min1, flicker_mid_max2);*

  • // random time for mid*

  • flicker_random_mid = random(flicker_low_min3, flicker_low_max4);*

  • //----------*

  • //high flicker algorithm*

  • flicker_random_high_start = random(flicker_high_min1, flicker_high_max2);*

  • flicker_random_high_end = random(flicker_high_min1, flicker_high_max2);*

  • // random time for high*

  • flicker_random_high = random(flicker_high_min3, flicker_high_max4);*

  • //-----------*

  • // random time for speed*

  • flicker_random_speed_start = random(flicker_speed_min, flicker_speed_max);*

  • flicker_random_speed_end = random(flicker_speed_min, flicker_speed_max);*

  • // calculating ultrasonic distance*

  • distance1 = ultrasonic1.Ranging(CM);*

  • distance2 =ultrasonic2.Ranging(CM);*

  • // mapping brightness to distance*

  • brightness1 = map (distance1, 256, 70, 30, 256);*

  • brightness2 = map (distance2, 256, 70, 30, 256);*

  • // mapping ifs and exclusions*

  • if (distance1 > 550)distance1 = 550;*

  • if(brightness1>256)brightness1=255;*

  • if (brightness1< 30) brightness1 = 30;*

  • if (distance2 > 550)distance2 = 550;*

  • if(brightness2>256)brightness2=255;*

  • if (brightness2< 30) brightness2 = 30;*

//LED1

  • // low flicker write to LED1*
  • if (distance1 >= 300)*
  • {*
  • //map low brightness*
  • analogWrite (pwmLed1, brightness1);*
  • delayMicroseconds(500);*
  • //map low flicker*
  • for (int i = flicker_random_low_start; i<flicker_random_low; i++) {*
  • analogWrite(pwmLed1, i);*
  • delayMicroseconds(flicker_random_speed_start);*
  • }*
  • delay(random(flicker_hold_min, flicker_hold_max));*
  • // low flicker*
  • for (int i = flicker_random_low; i>=flicker_random_low_end; i--) {*
  • analogWrite(pwmLed1, i);*
  • delayMicroseconds(flicker_random_speed_end);*
  • }*
  • // pause*
  • delay(random(flicker_pause_min, flicker_pause_max));*
  • }*
  • // mid flicker write to LED*
  • if (distance1 <300)*
  • {*
  • //map mid brightness*
  • analogWrite (pwmLed1, brightness1);*
  • delayMicroseconds(500);*
  • //map mid flicker*
  • for (int i = flicker_random_mid_start; i<flicker_random_mid; i++) {*
  • analogWrite(pwmLed1, i);*
  • delayMicroseconds(flicker_random_speed_start);*
  • }*
  • delay(random(flicker_hold_min, flicker_hold_max));*
  • // mid flicker*
  • for (int i = flicker_random_mid; i>=flicker_random_mid_end; i--) {*
  • analogWrite(pwmLed1, i);*
  • delayMicroseconds(flicker_random_speed_end);*
  • }*
  • // pause*
  • delay(random(flicker_pause_min, flicker_pause_max));*
  • }*
  • // high flicker write to LED*
  • if (distance1 < 200 )*
  • {*
  • //map high brightness*
  • analogWrite (pwmLed1, brightness1);*
  • delayMicroseconds(500);*
  • // map high flicker*
  • for (int i = flicker_random_high_start; i<flicker_random_high; i++) {*
  • analogWrite(pwmLed1, i);*
  • delayMicroseconds(flicker_random_speed_start);*
  • }*
  • // hold*
  • delay(random(flicker_hold_min, flicker_hold_max));*
  • // high flicker*
  • for (int i = flicker_random_high; i>=flicker_random_high_end; i--) {*
  • analogWrite(pwmLed1, i);*
  • delayMicroseconds(flicker_random_speed_end);*
  • }*
  • // pause*
  • delay(random(flicker_pause_min, flicker_pause_max));*
  • }*
  • // LED off*
  • if (distance1 <70)*
  • {*
  • analogWrite (pwmLed1, brightness1);*
  • delay (10000);*
  • } *
  • //LED2*
  • // low flicker write to LED2*
  • if (distance2 >= 300)*
  • {*
  • //map low brightness*
  • analogWrite (pwmLed2, brightness2);*
  • delayMicroseconds(500);*
  • //map low flicker*
  • for (int i = flicker_random_low_start; i<flicker_random_low; i++) {*
  • analogWrite(pwmLed2, i);*
  • delayMicroseconds(flicker_random_speed_start);*
  • }*
  • delay(random(flicker_hold_min, flicker_hold_max));*
  • // low flicker*
  • for (int i = flicker_random_low; i>=flicker_random_low_end; i--) {*
  • analogWrite(pwmLed2, i);*
  • delayMicroseconds(flicker_random_speed_end);*
  • }*
  • // pause*
  • delay(random(flicker_pause_min, flicker_pause_max));*
  • }*
    // mid flicker write to LED
  • if (distance2 <300)*
  • {*
  • //map mid brightness*
  • analogWrite (pwmLed2, brightness2);*
  • delayMicroseconds(500);*
  • //map mid flicker*
  • for (int i = flicker_random_mid_start; i<flicker_random_mid; i++) {*
  • analogWrite(pwmLed2, i);*
  • delayMicroseconds(flicker_random_speed_start);*
  • }*
  • delay(random(flicker_hold_min, flicker_hold_max));*
  • // mid flicker*
  • for (int i = flicker_random_mid; i>=flicker_random_mid_end; i--) {*
  • analogWrite(pwmLed2, i);*
  • delayMicroseconds(flicker_random_speed_end);*
  • }*
  • // pause*
  • delay(random(flicker_pause_min, flicker_pause_max));*
  • }*
    // high flicker write to LED
  • if (distance2 < 200 )*
  • {*
  • //map high brightness*
  • analogWrite (pwmLed2, brightness2);*
  • delayMicroseconds(500);*
  • // map high flicker*
  • for (int i = flicker_random_high_start; i<flicker_random_high; i++) {*
  • analogWrite(pwmLed2, i);*
  • delayMicroseconds(flicker_random_speed_start);*
  • }*
  • // hold*
  • delay(random(flicker_hold_min, flicker_hold_max));*
  • // high flicker*
  • for (int i = flicker_random_high; i>=flicker_random_high_end; i--) {*
  • analogWrite(pwmLed2, i);*
  • delayMicroseconds(flicker_random_speed_end);*
  • }*
  • // pause*
  • delay(random(flicker_pause_min, flicker_pause_max));*
  • }*
  • // LED off*
  • if (distance2 <70)*
  • {*
  • analogWrite (pwmLed2, brightness2);*
  • delay (10000);*
  • } *
  • Serial.print(ultrasonic1.Ranging(CM));*
  • Serial.print("cm");*
  • Serial.print(" : ");*
  • Serial.print(brightness1);*
  • Serial.print(" --- ");*
  • Serial.print(ultrasonic2.Ranging(CM));*
  • Serial.print("cm");*
  • Serial.print(" : ");*
  • Serial.print(brightness2);*
  • Serial.println(" --- ");*
  • delay (5);*
    }

Don't cross post. You already have a thread in the Project Guidance section.