/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// include the library code:
#include <LiquidCrystal.h>
//
//define variables
//
int lcdcols = 20;
int lcdrows = 4;
int delaytime = 1000;
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA7, 0x3E }; //ACTUAL MAC ADDR of my Arduino
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// set up the LCD's number of columns and rows; clear display and set the cursor position.
lcd.begin(lcdcols, lcdrows);
lcd.clear();
lcd.setCursor(0,0);
//initial Project Message prints here.
lcd.print("DHCP IP Grabber.");
delay(delaytime); // delay so we can confirm its working.
lcd.clear(); // clear display
lcd.print("Obtaining IP...");
delay(delaytime);
lcd.clear();
lcd.print("Network Address: "); //
lcd.setCursor(0,1);
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address
Serial.println("Network Address: "); // This is sent to serial, and shows correctly
//
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC); //this shows up fine in Arduino IDE window...
lcd.print(Ethernet.localIP()[thisByte], DEC); // I GET GIBBERISH HERE>>
Serial.print(".");
lcd.print("."); //
}
Serial.println();
}
void loop() {
}
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
//
//define variables
//
int lcdcols = 20;
int lcdrows = 4;
int delaytime = 1000;
int valread;
String clientMsg ="";
String flag1 ="N";
int ledPin1=8; //设定控制LED的数字IO脚
String flag2 ="N";
int ledPin2=9; //设定控制LED的数字IO脚
String flag3 ="N";
int ledPin3=13; //设定控制LED的数字IO脚
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA7, 0x3E }; //ACTUAL MAC ADDR of my Arduino
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
int serverPort=56788;
// Initialize the Ethernet server library
// with the IP address and port you want to use
EthernetServer server(serverPort);
void setup() {
pinMode(ledPin1,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin2,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
// start the serial for debugging
// start the Ethernet connection and the server:
// set up the LCD's number of columns and rows; clear display and set the cursor position.
lcd.begin(lcdcols, lcdrows);
lcd.clear();
lcd.setCursor(0,0);
//initial Project Message prints here.
lcd.print("DHCP IP Grabber.");
delay(delaytime); // delay so we can confirm its working.
lcd.clear(); // clear display
lcd.print("Obtaining IP...");
delay(delaytime);
lcd.clear();
lcd.print("Network Address: "); //
lcd.setCursor(0,1);
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address
Serial.println("Network Address: "); // This is sent to serial, and shows correctly
//
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC); //this shows up fine in Arduino IDE window...
lcd.print(Ethernet.localIP()[thisByte], DEC); // I GET GIBBERISH HERE>>
Serial.print(".");
lcd.print("."); //
}
Ethernet.begin(mac, Ethernet.localIP());
server.begin();
Serial.println("Server started");//log
Serial.println();
}
void loop() {
client = server.available();
if (client) {
if (client.connected()) {
while (client.available()) {
char c = client.read();
//Serial.print(c);
clientMsg+=c;//store the recieved chracters in a string
//if the character is an "end of line" the whole message is recieved
if (c == '\n') {
if(clientMsg.indexOf('1')>-1){
//Serial.println("test123");//log
digitalWrite(ledPin1,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.indexOf('A')>-1){
digitalWrite(ledPin1,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.indexOf('2')>-1){
//Serial.println("test123");//log
digitalWrite(ledPin2,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.indexOf('B')>-1){
digitalWrite(ledPin2,LOW); //设定PIN5脚为LOW = 0V
}
clientMsg ="";
}
}
}
// give the Client time to receive the data
delay(1);
// close the connection:
client.stop();
}
valread=analogRead(1);
if(valread<150){
digitalWrite(ledPin1,LOW); //设定PIN5脚为LOW = 0V
Serial.println(valread);
}
delay(200);
}
将模拟口转成数字口使用,补上两个继电器的接口:
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
//
//define variables
//
int lcdcols = 20;
int lcdrows = 4;
int delaytime = 1000;
int valread;
String clientMsg ="";
String flag1 ="N";
int ledPin1=8; //设定控制LED的数字IO脚
String flag2 ="N";
int ledPin2=9; //设定控制LED的数字IO脚
String flag3 ="N";
int ledPin3=18; //设定控制LED的数字IO脚
String flag4 ="N";
int ledPin4=19; //设定控制LED的数字IO脚
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA7, 0x3E }; //ACTUAL MAC ADDR of my Arduino
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
int serverPort=56788;
// Initialize the Ethernet server library
// with the IP address and port you want to use
EthernetServer server(serverPort);
void setup() {
pinMode(ledPin1,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin2,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin3,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin4,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
// start the serial for debugging
// start the Ethernet connection and the server:
// set up the LCD's number of columns and rows; clear display and set the cursor position.
lcd.begin(lcdcols, lcdrows);
lcd.clear();
lcd.setCursor(0,0);
//initial Project Message prints here.
lcd.print("DHCP IP Grabber.");
delay(delaytime); // delay so we can confirm its working.
lcd.clear(); // clear display
lcd.print("Obtaining IP...");
delay(delaytime);
lcd.clear();
lcd.print("Network Address: "); //
lcd.setCursor(0,1);
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address
Serial.println("Network Address: "); // This is sent to serial, and shows correctly
//
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC); //this shows up fine in Arduino IDE window...
lcd.print(Ethernet.localIP()[thisByte], DEC); // I GET GIBBERISH HERE>>
Serial.print(".");
lcd.print("."); //
}
Ethernet.begin(mac, Ethernet.localIP());
server.begin();
Serial.println("Server started");//log
Serial.println();
}
void loop() {
client = server.available();
if (client) {
if (client.connected()) {
while (client.available()) {
char c = client.read();
//Serial.print(c);
clientMsg+=c;//store the recieved chracters in a string
//if the character is an "end of line" the whole message is recieved
if (c == '\n') {
if(clientMsg.indexOf('1')>-1){
//Serial.println("test123");//log
digitalWrite(ledPin1,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.indexOf('A')>-1){
digitalWrite(ledPin1,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.indexOf('2')>-1){
//Serial.println("test123");//log
digitalWrite(ledPin2,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.indexOf('B')>-1){
digitalWrite(ledPin2,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.indexOf('3')>-1){
//Serial.println("test123");//log
digitalWrite(ledPin3,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.indexOf('C')>-1){
digitalWrite(ledPin3,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.indexOf('4')>-1){
//Serial.println("test123");//log
digitalWrite(ledPin4,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.indexOf('D')>-1){
digitalWrite(ledPin4,LOW); //设定PIN5脚为LOW = 0V
}
clientMsg ="";
}
}
}
// give the Client time to receive the data
delay(1);
// close the connection:
client.stop();
}
valread=analogRead(1);
if(valread<150){
digitalWrite(ledPin1,LOW); //设定PIN5脚为LOW = 0V
Serial.println(valread);
}
delay(200);
}
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
//
//define variables
//
int lcdcols = 20;
int lcdrows = 4;
int delaytime = 1000;
int valread;
String clientMsg ="";
String flag1 ="N";
int ledPin1=8; //设定控制LED的数字IO脚
String flag2 ="N";
int ledPin2=9; //设定控制LED的数字IO脚
String flag3 ="N";
int ledPin3=18; //设定控制LED的数字IO脚
String flag4 ="N";
int ledPin4=19; //设定控制LED的数字IO脚
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA7, 0x3E }; //ACTUAL MAC ADDR of my Arduino
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
int serverPort=56788;
// Initialize the Ethernet server library
// with the IP address and port you want to use
EthernetServer server(serverPort);
void setup() {
pinMode(ledPin1,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin2,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin3,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin4,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
// start the serial for debugging
// start the Ethernet connection and the server:
// set up the LCD's number of columns and rows; clear display and set the cursor position.
lcd.begin(lcdcols, lcdrows);
lcd.clear();
lcd.setCursor(0,0);
//initial Project Message prints here.
lcd.print("DHCP IP Grabber.");
delay(delaytime); // delay so we can confirm its working.
lcd.clear(); // clear display
lcd.print("Obtaining IP...");
delay(delaytime);
lcd.clear();
lcd.print("Network Address: "); //
lcd.setCursor(0,1);
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address
Serial.println("Network Address: "); // This is sent to serial, and shows correctly
//
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC); //this shows up fine in Arduino IDE window...
lcd.print(Ethernet.localIP()[thisByte], DEC); // I GET GIBBERISH HERE>>
Serial.print(".");
lcd.print("."); //
}
Ethernet.begin(mac, Ethernet.localIP());
server.begin();
Serial.println("Server started");//log
Serial.println();
}
void loop() {
client = server.available();
if (client) {
if (client.connected()) {
while (client.available()) {
char c = client.read();
//Serial.print(c);
clientMsg+=c;//store the recieved chracters in a string
//if the character is an "end of line" the whole message is recieved
if (c == '\n') {
if(clientMsg.startsWith("1open")){
//Serial.println("test123");//log
digitalWrite(ledPin1,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("1close")){
digitalWrite(ledPin1,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.startsWith("2open")){
//Serial.println("test123");//log
digitalWrite(ledPin2,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("2close")){
digitalWrite(ledPin2,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.startsWith("3open")){
//Serial.println("test123");//log
digitalWrite(ledPin3,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("3close")){
digitalWrite(ledPin3,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.startsWith("4open")){
//Serial.println("test123");//log
digitalWrite(ledPin4,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("4close")){
digitalWrite(ledPin4,LOW); //设定PIN5脚为LOW = 0V
}
clientMsg ="";
}
}
}
// give the Client time to receive the data
delay(1);
// close the connection:
client.stop();
}
valread=analogRead(1);
if(valread<150){
digitalWrite(ledPin1,LOW); //设定PIN5脚为LOW = 0V
Serial.println(valread);
}
delay(200);
}
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
//
//define variables
//
int lcdcols = 20;
int lcdrows = 4;
int delaytime = 1000;
int valread;
String clientMsg ="";
String flag1 ="N";
int ledPin1=8; //设定控制LED的数字IO脚
String flag2 ="N";
int ledPin2=9; //设定控制LED的数字IO脚
String flag3 ="N";
int ledPin3=18; //设定控制LED的数字IO脚
String flag4 ="N";
int ledPin4=19; //设定控制LED的数字IO脚
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0xA0, 0xA7, 0x3E }; //ACTUAL MAC ADDR of my Arduino
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
int serverPort=56788;
// Initialize the Ethernet server library
// with the IP address and port you want to use
EthernetServer server(serverPort);
void setup() {
pinMode(ledPin1,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin2,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin3,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
pinMode(ledPin4,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
// start the serial for debugging
// start the Ethernet connection and the server:
// set up the LCD's number of columns and rows; clear display and set the cursor position.
lcd.begin(lcdcols, lcdrows);
lcd.clear();
lcd.setCursor(0,0);
//initial Project Message prints here.
lcd.print("DHCP IP Grabber.");
delay(delaytime); // delay so we can confirm its working.
lcd.clear(); // clear display
lcd.print("Obtaining IP...");
delay(delaytime);
lcd.clear();
lcd.print("Network Address: "); //
lcd.setCursor(0,1);
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address
Serial.println("Network Address: "); // This is sent to serial, and shows correctly
//
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC); //this shows up fine in Arduino IDE window...
lcd.print(Ethernet.localIP()[thisByte], DEC); // I GET GIBBERISH HERE>>
Serial.print(".");
lcd.print("."); //
}
Ethernet.begin(mac, Ethernet.localIP());
server.begin();
Serial.println("Server started");//log
Serial.println();
}
void loop() {
client = server.available();
if (client) {
if (client.connected()) {
while (client.available()) {
char c = client.read();
//Serial.print(c);
clientMsg+=c;//store the recieved chracters in a string
//if the character is an "end of line" the whole message is recieved
if (c == '\n') {
if(clientMsg.startsWith("1open")){
//Serial.println("test123");//log
digitalWrite(ledPin1,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("1close")){
digitalWrite(ledPin1,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.startsWith("2open")){
//Serial.println("test123");//log
digitalWrite(ledPin2,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("2close")){
digitalWrite(ledPin2,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.startsWith("3open")){
//Serial.println("test123");//log
digitalWrite(ledPin3,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("3close")){
digitalWrite(ledPin3,LOW); //设定PIN5脚为LOW = 0V
}
if(clientMsg.startsWith("4open")){
//Serial.println("test123");//log
digitalWrite(ledPin4,HIGH); //设定PIN5脚为HIGH = 5V左右
}else if(clientMsg.startsWith("4close")){
digitalWrite(ledPin4,LOW); //设定PIN5脚为LOW = 0V
}
clientMsg ="";
}
}
}
// give the Client time to receive the data
delay(1);
// close the connection:
client.stop();
}
valread=analogRead(1);
if(valread<150){
digitalWrite(ledPin1,HIGH); //设定PIN5脚为LOW = 0V
Serial.println(valread);
}
delay(200);
}