Wave Machine: Delayed actions and cannot get ethernet to work

Hi, I'm building a machine for a computer processing class that is a wave tank that generates waves based on two different modes.

The project is based on these two projects I found online:

Wave Buoy

Wave Tank

In one mode the tank generates waves based on your hand's proximity to the proximity sensor. In the other mode the tank generates waves based on readings from a rss feed. I'm having some problems tho.

a) The ethernet mode based on the buoy just doesn't work. The servos just click and don't really move and the LEDs don't light up based on the Significant wave height.

b) Proximity mode works, but there is a large lag. For instance, the waves can be going really slow and I'll put my hand really close. Then it will take a few seconds for the Arduino to speed up the servos and change the LED instead of doing it faster.

Any help would be greatly appreciated.

These are the parts im using

Ethernet Shield

Sensor

blue led button

[Amazon.com](http://green led button)

Here is my code:

//variable for proximity sensor reads
int trigPin = 11;    // Trigger
int echoPin = 12;    // Echo
long duration, cm, inches;
 
//Servo
//import the library
#include <Servo.h>
//declare servos
//pin 5
Servo servoLeft;
//pin 6 
Servo servoRight;
//Servo position variables
int pos = 20;
int post = 160;
int back = 20;
int forward = 160;
//speed
int spe;

//LED Variables
int red = 2;
int green = 3;
int blue = 4;

//Ethernet
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char serverName[] = "ndbc.noaa.gov";
EthernetClient client;
float waveHeight; // float value that holds wave height

void setup() {
  //declare ins and outs of blue led button
  pinMode(13, OUTPUT);  //led in button
  pinMode(10, INPUT);   //button to change mode from buoy to proximity

  Serial.begin(9600);
  
  //attach servos
  servoLeft.attach(5);
  servoRight.attach(6);
  
  //declare input/output of proximity sensor
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  //declare LED outputs
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);

  //Ethernet
  if (Ethernet.begin(mac) == 0)
  { // start ethernet using mac & IP address
    while(true) ;
  }
  delay(2000); // give the Ethernet shield 2 second to initialize

  //Declare all LEDs off to begin
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);

  //Set Servos to base position
  servoLeft.write(back);
  servoRight.write(back);
  
}

void loop() {

  //Set serial to print proximity sensor data
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();

  //Move servos and have speed correspond to speed. If statements in buoy will change speed based on wave height and in handMode will change based on proximity.
     for (pos = back; pos <= forward; pos += 1) {
      servoLeft.write(pos);
      servoRight.write(pos);
      delay(spe);
     }
     for (pos = forward; pos >= back; pos -= 1) {
      servoLeft.write(pos);
      servoRight.write(pos);
      delay(spe);
     }


     
  //if blue button pushed then use proximity sensor to create wave speed
  if (digitalRead(10) == HIGH) {
    digitalWrite(13, HIGH);
        //use proxity sensor
        // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
        // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
        digitalWrite(trigPin, LOW);
        delayMicroseconds(5);
        digitalWrite(trigPin, HIGH);
        delayMicroseconds(10);
        digitalWrite(trigPin, LOW);
 
        // Read the signal from the sensor: a HIGH pulse whose
        // duration is the time (in microseconds) from the sending
        // of the ping to the reception of its echo off of an object.
        pinMode(echoPin, INPUT);
        duration = pulseIn(echoPin, HIGH);
 
        // Convert the time into a distance
        cm = (duration/2) / 29.1;     // Divide by 29.1 or multiply by 0.0343
        inches = (duration/2) / 74;   // Divide by 74 or multiply by 0.0135

      //based on proximity sensor readings, set wave speed accordingly; the closer object the faster the waves
      if ((inches>=0) && (inches <1)) {
        spe = 1;
      } else if ((inches>=1) && (inches <2)) {
        spe = 2;
      } else if ((inches>=2) && (inches <3)) {
        spe = 3;
      } else if ((inches>=3) && (inches <4)) {
        spe = 4;
      } else if ((inches>=4) && (inches <5)) {
        spe = 5;
      } else if ((inches>=5) && (cm <inches)) {
        spe = 6;
      } else if ((inches>=6) && (inches <7)) {
        spe = 7;
      } else if ((inches>=7) && (inches <8)) {
        spe = 8;
      } else if ((inches>=8) && (inches <9)) {
        spe = 9;
      } else if ((inches>=9) && (inches <10)) {
        spe = 10;
      } else if ((inches>=10) && (inches <11)) {
        spe = 11;
      } else if ((inches>=11) && (inches <12)) {
        spe = 12;
      } else if ((inches>=12) && (inches <13)) {
        spe = 13;
      } else if ((inches>=13) && (inches <14)) {
        spe = 14;
      } else if ((inches>=14) && (inches <15)) {
        spe = 15;
      } else if ((inches>=15) && (inches <16)) {
        spe = 16;
      } else if ((inches>=16) && (inches <17)) {
        spe = 17;
      } else if ((inches>=17) && (inches <18)) {
        spe = 18;
      } else if ((inches>=18) && (inches <19)) {
        spe = 19;
      } else if ((inches>=19) && (inches <20)) {
        spe = 20;
      } else if ((inches>=20) && (inches <21)) {
        spe = 21;
      } else if ((inches>=21) && (inches <100)) {
        spe = 22;
      }
      //after 21 inches it felt kind of irrelevant

      //light up RGB depending on proximity
      if ((inches>=10)&&(inches<100)) {
        digitalWrite(red   ,LOW);
        digitalWrite(green ,LOW);
        digitalWrite(blue  ,HIGH);
      }
      if ((inches>=4)&&(inches<10)) {
        digitalWrite(red   ,LOW);
        digitalWrite(green ,HIGH);
        digitalWrite(blue  ,LOW);
      }
      if ((inches>=0)&&(inches<4)) {
        digitalWrite(red   ,HIGH);
        digitalWrite(green ,LOW);
        digitalWrite(blue  ,LOW);
      }

  //if the button isn't pushed, the wave speed of the tank will be determined upon the waves from live buoy data
  } else {
    digitalWrite(13, LOW);
    inches = 100;
    cm = 200;

   //use buoy
      
      //this code grabs the wave height and puts in within the variable
      if (client.connect(serverName, 80)>0) {
        client.println("GET https://www.ndbc.noaa.gov/data/latest_obs/44097.rss");
      }
      if (client.connected()) {
        if(client.find("Significant Wave Height:")) {
      //look for the wave height and pass the value to variable
      waveHeight = client.parseFloat();
        }
      }

      //light up RGB depending on waveHeight
      if ((waveHeight>=0)&&(waveHeight<3)) {
        digitalWrite(red   ,LOW);
        digitalWrite(green ,LOW);
        digitalWrite(blue  ,HIGH);
      }
      if ((waveHeight>=3)&&(waveHeight<8)) {
        digitalWrite(red   ,LOW);
        digitalWrite(green ,HIGH);
        digitalWrite(blue  ,LOW);
      }
      if ((waveHeight>=8)&&(waveHeight<100)) {
        digitalWrite(red   ,HIGH);
        digitalWrite(green ,LOW);
        digitalWrite(blue  ,LOW);
      }

      //set speed based on varying waveHieghts
      if ((waveHeight>=0) && (waveHeight <1)) {
        spe = 12;
      } else if ((waveHeight>=1) && (waveHeight <2)) {
        spe = 8;
      } else if ((waveHeight>=2) && (waveHeight <3)) {
        spe = 7;
      } else if ((waveHeight>=3) && (waveHeight <4)) {
        spe = 6;
      } else if ((waveHeight>=4) && (waveHeight <5)) {
        spe = 5;
      } else if ((waveHeight>=5) && (waveHeight <6)) {
        spe = 4;
      } else if ((waveHeight>=6) && (waveHeight <7)) {
        spe = 3;
      } else if ((waveHeight>=7) && (waveHeight <8)) {
        spe = 2;
      } else if ((waveHeight>=8) && (waveHeight <100)) {
        spe = 1;
      }*/
  }
  
}