My new code is below and something just doesnt seem right...now and again 1/10 it connects but writes the wrong pin the present data of Significant Wave Height: 6.2 ft & Average Period: 6 sec should result in a slighly fading blue LED (pin 6) but it flashes green on pin 5...ive tried as much as i can and am stumped
Thanks
This is the original code http://www.instructables.com/files/orig/F47/RB93/HXZN70FQ/F47RB93HXZN70FQ.ino
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char serverName[] = "ndbc.noaa.gov";
EthernetClient client;
boolean time=false;
int long wavetime;
int red=3,green=5,blue=6; // PWM pins initialized to pass values of RGB
float waveheight; // float value that holds wave height
int avgp;
void setup()
{
Serial.begin(9600);
pinMode(red ,OUTPUT);
pinMode(green ,OUTPUT);
pinMode(blue ,OUTPUT);
if (Ethernet.begin(mac) == 0)
{ // start ethernet using mac & IP address
while(true) ;
}
delay(2000); // give the Ethernet shield 2 second to initialize
}
void loop()
{
if (client.connect(serverName, 80)>0) {
client.println("GET http://www.ndbc.noaa.gov/data/latest_obs/62081.rss");
}
if (client.connected()) {
if(client.find("Significant Wave Height:") && client.find("Average Period:"))
{//look for the wave height and pass the value to variable
waveheight = client.parseFloat();
avgp = client.parseInt();
}
else{
digitalWrite(13,HIGH);
}
//The code below lights up RGB module light depending on the wave height
if ((waveheight>=0)&&(waveheight<3))
{
if (avgp<=10)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,0 );
analogWrite(green ,i);
analogWrite(blue ,0);
delay(30);
if(i==255)
{
i=0;
}
}
if (avgp>=10&&avgp<=15)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,0 );
analogWrite(green ,i);
analogWrite(blue ,0);
delay(10);
if(i==255)
{
i=0;
}
if (avgp>=15)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,0 );
analogWrite(green ,i);
analogWrite(blue ,0);
delay(5);
if(i==255)
{
i=0;
}
}
}
};
}
if ((waveheight>=3)&&(waveheight<8))
{
if (avgp<=10)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,0 );
analogWrite(green ,0);
analogWrite(blue ,i);
delay(5);
if(i==255)
{
i=0;
}
}
if (avgp>=10&&avgp<=15)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,0 );
analogWrite(green ,0);
analogWrite(blue ,i);
delay(10);
if(i==255)
{
i=0;
}
if (avgp>=15)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,0 );
analogWrite(green ,0);
analogWrite(blue ,i);
delay(20);
if(i==255)
{
i=0;
}
}
}
};
if ((waveheight>=8)&&(waveheight<100))
{
if (avgp<=10)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,i );
analogWrite(green ,0);
analogWrite(blue ,0);
delay(20);
if(i==255)
{
i=0;
}
}
if (avgp>=10&&avgp<=15)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,i );
analogWrite(green ,0);
analogWrite(blue ,0);
delay(10);
if(i==255)
{
i=0;
}
if (avgp>=15)
{
for(int i=0;i<=255;i++)
{
analogWrite(red ,i );
analogWrite(green ,0);
analogWrite(blue ,0);
delay(5);
if(i==255)
{
i=0;
}
}
}
client.stop();//Disconnect
}
}
}
}
}
}
}
}
}
}
}