Yes I have a new Arduino Ethernet Shiled with the Wiznet 5100. I did include the Ethernet.h library. Here's my pre-ethernet code:
/*
Countdown sketch using Ascii input and Ascii output
*/
int pw_out = 12;
int sip = 0; // seconds user input
int mip = 0; // minutes user input
int hip = 0; // hours user input
int secs = 0; // Calculated Seconds for countdown output
int mins = 0; // Calculated Minutes for countdown output
int hours = 0; // Calculated Hours for countdown output
unsigned long T =0; // Current Count Down Time in Seconds
unsigned long TR = 0; // Time Run since count down started
unsigned long intmillis = 0; // initial "millis" reading used to calculate TR
int t = 0; // variable
int s = 0; // variable
int S = 0; // variable
int m = 0; // variable
int M = 0; // variable
int h = 0; // variable
int Mode = 0; // Mode Variable
//int incomingByte =0;
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(pw_out, OUTPUT);
}
void loop() {
sip=0;
mip=0;
hip=0;
Mode=0;
//incomingByte = 0;
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial. Input as h,m,s :
int hip= Serial.parseInt();
// do it again:
int mip= Serial.parseInt();
// do it again:
int sip= Serial.parseInt();
// do it again:
int Mode= Serial.parseInt();
if (Serial.read() == '\n') // look for the newline. That's the end of your time input.
{
T = (sip) + (mip*60) + (hip*3600); // Total user input Time in seconds.
intmillis = millis(); // reinitalizes a new time reference at the start of a new count down loop.
TR =0; // reinitalizes TR (TimeRun) for next user input countdown.
while (secs >=0) // If countdown is greater than "0" seconds keep generating code.
{
if (Mode==0) TR = (millis() - intmillis)/1000;
// time Count Down loop has been running since start (in seconds).
secs = T - TR; //Calculate seconds
mins=secs/60; //convert seconds to minutes
hours=mins/60; //convert minutes to hours
secs=secs-(mins*60); //subtract the coverted seconds to minutes in order to display 59 secs max
mins=mins-(hours*60); //subtract the coverted minutes to hours in order to display 59 minutes max
if (secs < 0) // Forces Dispaly to 'loop' 0:00:00 when time has rundown to zero.
{
secs = 0;
mins = 0;
hours = 0; //
}
else
M= (mins/10); // changes the 2-digit mins and secs characters into M,m & S,s format.
m= (mins%10);
S= (secs/10);
s= (secs%10);
Serial.print(hours); //writes hours value to serial monitor
Serial.print(":"); //writes :
Serial.print(M); //writes Minutes Decade value to serial monitor
Serial.print(m); //writes Minutes Unit value to serial monitor//writes :
Serial.print(":"); //writes :
Serial.print(S); //writes Seconds Decade value to serial monitor
Serial.print(s); //writes Seconds Unit value to serial monitor//writes :
Serial.println(); //prints line return
// the following code writes a serial bit stream to pin 12 that is Pulse Width Coded. A "1" bit is 556us ON and 277us OFF. A "0" bit is the opposite, 277us ON and 566us OFF.
//loads "0" into the display's 10ths digit.
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
switch (s) {
case 0:
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
digitalWrite(pw_out, HIGH); // LOW
delayMicroseconds(277);
digitalWrite(pw_out, LOW);
delayMicroseconds(556);
break;
case 1:
digitalWrite(pw_out, HIGH); // HIGH
// I've removed the rest of the CASE statements to allow my code to fit the size limit in this POST
digitalWrite(pw_out, HIGH); // Unused Bit. Always "1"
delayMicroseconds(556);
digitalWrite(pw_out, LOW);
delayMicroseconds(277);
delayMicroseconds(1500); //1.5ms Short Interword Gap.
// if there's any serial available, read it:
if (Serial.available() > 0) {
// incomingByte = Serial.read();
break;
}
}
}
}
}
I modified this so that my Network Shield would echo back the serial input:
#include <SPI.h>
#include <Ethernet.h>
/*
Countdown sketch using Ascii input and Ascii output
*/
// network configuration. gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x32, 0x36 };
//the IP address for the shield:
byte ip[] = { 10, 0, 0, 55 };
// the router's gateway address:
byte gateway[] = { 10, 0, 0, 1 };
// the subnet:
byte subnet[] = { 255, 255, 0, 0 };
// telnet defaults to port 23
EthernetServer server = EthernetServer(23);
int pw_out = 12;
int sip = 0; // seconds user input
Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(pw_out, OUTPUT);
}
void loop() {
Again I had to remove most of the code to fit the 9500 character limit. It does show how I added the Network stuff.
I added this code to the orig sketch to echo the serial output. It does send the data to the IP client.
client.print(hours); //writes hours value to serial monitor
client.print(":"); //writes :
client.print(M); //writes Minutes Decade value to serial monitor
client.print(m); //writes Minutes Unit value to serial monitor//writes :
client.print(":"); //writes :
client.print(S); //writes Seconds Decade value to serial monitor
client.print(s); //writes Seconds Unit value to serial monitor//writes :
client.println(); //prints line return
So you see it's a bit of a mess. I warned you. Seeing my working serial code, how do I add the network stuff to allow ip data entery?