当我使用Ethernet.begin(mac,ip)时,led不会打开和关闭。但是,当我不使用那条线时,它的工作原理。但我需要通过使用以太网和UPP模块来开启和关闭。我怎么样?
主板型号:以太网08 Twinker套件,Twinker继电器
#include <TinkerKit.h>
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
TKLed led(O5); //O0 does not work
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888; // local port to listen on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "ackv1"; // a string to send back
EthernetUDP Udp;
void setup() {
Ethernet.begin(mac,ip);
Udp.begin(localPort);
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize)
{
// check the switch state
delay(1000);
led.off();
delay(3000);
led.on();
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
}
编辑:
$ echo "hello" | nc -4u 192.168.1.177 8888
ackv1
答案 0 :(得分:1)
从您的描述中可以看出,以太网I / O干扰了LED I / O.
请注意:
TKLed led(O0);
这可能将led定义为端口0.您需要确定以太网使用的端口。 (我会告诉你,但这是一个很好的教训。)
如果你需要阅读文档,那么在led端口号和以太网端口号之间存在冲突,那么你需要移动LED,因为以太网端口需要串行I / O,而LED需要一个+ 5V或0V。