本帖最后由 tsaiwn 于 2015-4-13 19:26 编辑
布列松 发表于 2015-4-12 15:37 
能不能完整的帮忙改一遍,我今天改了半天也没改好 - #include <EtherCard.h>
-
- static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x31};
- static byte myip[] = {192,168,1,180};
- byte Ethernet::buffer[700];
-
- const int ledPin = 3;
- boolean ledStatus;
-
- char* on = "ON";
- char* off = "OFF";
- char* statusLabel;
- char* buttonLabel;
- unsigned char hexdata[8] = {0x01,0x05,0x00,0x10,0xFF,0x00,0x8D,0xFF};
- unsigned char yy[] = {0x0 ? ? ? ? ? ? ?? ?? ? };
-
- void setup () {
-
- Serial.begin(9600);
- Serial.println("WebLed Demo");
-
- if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
- Serial.println( "Failed to access Ethernet controller");
- else
- Serial.println("Ethernet controller initialized");
-
- if (!ether.staticSetup(myip))
- Serial.println("Failed to set IP address");
-
- Serial.println();
-
- pinMode(ledPin, OUTPUT);
- digitalWrite(ledPin, LOW);
- ledStatus = false;
- }
-
- void loop() {
-
- word len = ether.packetReceive();
- word pos = ether.packetLoop(len);
- doLed(pos);
- doLed2(pos);
- doLed3(pos);
- doLed4(pos);
-
- BufferFiller bfill = ether.tcpOffset();
- /////
- bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
- "<html><head><title>WebLed</title></head>"
- "<body>"
- "LED Status: $S "
- "<a href="/?status=$S"><input type="button" value="$S"></a>"
- "<br><br>"
- "LED2 Status: $S "
- "<a href="/?status2=$S"><input type="button" value="$S"></a>"
- "<br><br>"
- "LED3 Status: $S "
- "<a href="/?status3=$S"><input type="button" value="$S"></a>"
- "<br><br>"
- "LED4 Status: $S "
- "<a href="/?status4=$S"><input type="button" value="$S"></a>"
- "<br><br>"
- "</body></html>\r\n\r\n"
- ), statusLabel, buttonLabel, buttonLabel,
- statusLabel2, buttonLabel2, buttonLabel2,
- statusLabel3, buttonLabel3, buttonLabel3,
- statusLabel4, buttonLabel4, buttonLabel4,
- );
- /////
- ether.httpServerReply(bfill.position());
- }
- void doLed( word pos) {
- if(pos) {
- if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) {
- Serial.write(hexdata, 8);
- ledStatus = true;
- }
-
- if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 0) {
- Serial.write(yy, sizeof( yy ));
- ledStatus = false;
- }
-
- if(ledStatus) {
- digitalWrite(ledPin, HIGH);
- statusLabel = on;
- buttonLabel = off;
- } else {
- digitalWrite(ledPin, LOW);
- statusLabel = off;
- buttonLabel = on;
- }
- }
- }
- void doLed2( word pos ) {
- 自己參考以下改
- }
- void doLed3( word pos ) {
- 自己參考以下改
- }
- void doLed4(word pos ) {
- if(pos) {
- if(strstr((char *)Ethernet::buffer + pos, "GET /?status4=ON") != 0) {
- ??? ??? Serial.write(hexdata, 8);
- ledStatus4 = true;
- }
-
- if(strstr((char *)Ethernet::buffer + pos, "GET /?status4=OFF") != 0) {
- ??? ??? Serial.write(yy, sizeof( yy ));
- ledStatus4 = false;
- }
-
- if(ledStatus4) {
- digitalWrite(ledPin4, HIGH);
- statusLabel4 = on;
- buttonLabel4 = off;
- } else {
- digitalWrite(ledPin4, LOW);
- statusLabel4 = off;
- buttonLabel4 = on;
- }
- }
- }
复制代码 |