Go Down

Topic: Combining Sketches (Read 13963 times) previous topic - next topic

Carnyworld

Are you saying that If I only view the time once the other things will show? If so how do I do that?
C program run. C program crash. C programmer quit.

PaulS

Quote
Are you saying that If I only view the time once the other things will show?

The feed is showing, one character at a time. If you only show the time once, the other stuff will be more obvious, since it won't be hiding among all the time stuff.

Quote
If so how do I do that?

Put the code to display the time stuff in a function. Call that function when you want to show the time. It might make sense to make that function print the time in a more meaningful format, but that's up to you.

Carnyworld

How do I make a function?
C program run. C program crash. C programmer quit.

Carnyworld

Is it like this:

Code: [Select]
//zoomkat 12-22-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

#include <Time.h> 
#include <Wire.h> 
#include <DS1307RTC.h>
#include <SPI.h>
#include <Ethernet.h>
String readString, readString1;
int x=0;
char lf=10;

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0x22, 0x8A };
byte ip[] = {
  192, 168, 0, 104 };
byte server[] = {
  97, 74, 166, 239 };

Client client(server, 80);

void rtc()
{
  setSyncProvider(RTC.get);
}
void setup()
{
  byte gateway[] = {
    192, 168, 0, 1   };
  Ethernet.begin(mac, ip, gateway);
  Serial.begin(9600);
  Serial.println("starting simple arduino client test");
  Serial.println();
  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /processedfeed.aspx?feedcode=%5Bbc_u1%5Dhttp%253A//pipes.yahoo.com/pipes/pipe.run%253F_id%253D6d2c0b97b3c18eba6be661489a35c9c3%2526_render%253Drss%5B/bc_u1%5D%5Bbc_m1%5D3%5B/bc_m1%5D%5Bbc_o%5D0%5B/bc_o%5D HTTP/1.0");
    client.println();
  }
  else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    if (c==lf) x=(x+1);
    if (x==14) readString += c;
    readString += c;
  }

  if (!client.connected()) {
    client.stop();

    Serial.println("Current data row:" );
    Serial.print(readString);
    Serial.println();
    readString1 = (readString.substring(41,43));
    Serial.println();
    Serial.print("DPD sec: ");
    Serial.println(readString1);
    Serial.println("done");

    for(;;);

  }
  {
    digitalClockDisplay(); 
    delay(1000);
  }
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
C program run. C program crash. C programmer quit.

PaulS

Quote
Is it like this:


Code: [Select]
  {
    digitalClockDisplay(); 
    delay(1000);
  }

Almost. There is no reason for the curly braces and no reason for the delay. The time will be printed on each pass through loop, though. That is probably not what you want. I'd guess that you want to print the time that the feed arrived.

Code: [Select]
  if (client.available())
  {
    char c = client.read();
    readString += c;

    if (c==lf) x++;

    if (x==14)
    {
      digitalClockDisplay();
      Serial.print(readString);
    }
  }

I presume that the if(x==14) test is there because that represents the end of the feed data (14 lines have arrived). If not, why is it there?

Go Up