EtherCard 和 IRremote 同时使用,UNO,串口检测空白,无任何内容!
EtherCard 接线是按照:
这个图来接。
IRremote 接受器接线是 D3。我的构想是:红外接收头,收到按下遥控的数据,然后提交给EtherCard发送到网站,单独分别使用EtherCard或者IRremote测试都没有问题,但整合在一起时就出现问题了!是不是这算是库文件冲突吗?
代码内容如下:
- //>>> The latest version of this code can be found at https://github.com/jcw/ !!
- #include <IRremote.h>
- #include <EtherCard.h>
- // ethernet interface mac address, must be unique on the LAN
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
-
- byte Ethernet::buffer[700];
- static uint32_t timer;
- const char UserCode[] = "xxxx";
- const char PassWord[] = "xxxx";
- const char website[] = "www.xxxx.com";
- const char urlbuf[] = "/Index/xxxx";
-
- int RECV_PIN = 3;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- void setup () {
- Serial.begin(57600);
- Serial.println("\n[webClient]");
- if (!ether.begin(sizeof Ethernet::buffer, mymac,10))
- Serial.println( "Failed to access Ethernet controller");
- if (!ether.dhcpSetup())
- Serial.println("DHCP failed");
-
- ether.printIp("IP: ", ether.myip);
- ether.printIp("GW: ", ether.gwip);
- ether.printIp("DNS: ", ether.dnsip);
-
- if (!ether.dnsLookup(website))
- Serial.println("DNS failed");
- while (ether.clientWaitingGw()){
- ether.packetLoop(ether.packetReceive());
- Serial.println("Waitting for getaway...");
- }
- irrecv.enableIRIn();
- ether.printIp("SRV: ", ether.hisip);
- }
- // called when the client request is complete
- static void my_callback (byte status, word off, word len) {
- Serial.println(">>>");
- Ethernet::buffer[off+300] = 0;
- Serial.print((const char*) Ethernet::buffer + off);
- Serial.println("...");
- }
- void dump(decode_results *results) {
- int count = results->rawlen;
- String Codes = "user=";
- Codes += UserCode;
- Codes += ",passw=" ;
- Codes += PassWord;
- Codes += ";len=" + count ;
- Codes += ";code=";
- Serial.print("Raw (");
- Serial.print(count, DEC);
- Serial.print("): ");
- for (int i = 0; i < count; i++) {
- char str[8];
- if ((i % 2) == 1) {
- dtostrf(results->rawbuf[i]*USECPERTICK,8,0,str);
- }
- else {
- dtostrf((int) results->rawbuf[i]*USECPERTICK,8,0,str);
- }
- Serial.print(str);
- Serial.print(" ");
- Codes += str;
- }
- Codes += ";";
- char poststr[Codes.length()];
- char apikey[]="fuck";
- for(int i=0;i<=Codes.length();i++) poststr[i]=Codes.charAt(i);
- ether.httpPost(urlbuf,website,apikey,poststr,my_callback);
- }
- void loop () {
- ether.packetLoop(ether.packetReceive());
-
- if (irrecv.decode(&results)) {
- dump(&results);
- }
- irrecv.resume();
- }
复制代码 |