#define USE_NATIVE_ETHERNET
#define USE_ILI9341_T3N
//#define USE_ILI9341_T3
#ifdef USE_NATIVE_ETHERNET
// In NativeEthernet.cpp,EthernetClass::begin(...) you must remove waiting on the link status:
/// while(!link_status){
/// }
/// Otherwise the program will block until an ethernet cable is connected.
#include <NativeEthernet.h>
const byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
const IPAddress ip(192, 168, 1, 177);
const unsigned int local_port = 8888;
const IPAddress remote_ip(192, 168, 1, 1);
const uint16_t remote_port = 8888;
EthernetLinkStatus link_status = Unknown;
EthernetUDP Udp;
char packetBuffer[64];
#endif
#if defined(USE_ILI9341_T3) || defined(USE_ILI9341_T3N)
#if defined(USE_ILI9341_T3N)
#include "ILI9341_t3n.h"
ILI9341_t3n
#else
#include "ILI9341_t3.h"
ILI9341_t3
#endif
tft(38,//255, //uint8_t _CS,
28, // uint8_t _DC,
40,//255, //uint8_t _RST = 255,
26, //uint8_t _MOSI=11,
27, //uint8_t _SCLK=13,
39);//255); //uint8_t _MISO=12);tft(10, //uint8_t _CS,
#endif
void setup() {
while (!Serial);
Serial.begin(9600);
#ifdef USE_NATIVE_ETHERNET
Serial.println("calling Ethernet.begin");
Ethernet.begin(mac, ip);
Serial.println("Ethernet.begin finished");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet HW not found.");
while (true);
}
Serial.println("Ethernet HW found");
Udp.begin(local_port);
#endif
#if defined(USE_ILI9341_T3) || defined(USE_ILI9341_T3N)
Serial.println("initializing ILI9341");
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
tft.setCursor(10, tft.height()/4);
tft.setTextSize(2);
tft.setRotation(0);
tft.print("Initialized");
Serial.println("ILI9341 initialized");
#endif
}
unsigned int loop_count = 0;
void loop() {
#ifdef USE_NATIVE_ETHERNET
{
EthernetLinkStatus s = Ethernet.linkStatus();
if (s != link_status) {
link_status = s;
switch (link_status) {
case LinkON:
Serial.println("Ethernet cable connected.");
break;
case LinkOFF:
Serial.println("Ethernet cable disconnected.");
break;
default:
Serial.println("weird link status.");
}
}
}
unsigned int x = loop_count;
for (int i = 9; i >= 0; i--) {
packetBuffer[i] = '0' + (x % 10);
x /= 10;
}
Udp.beginPacket(remote_ip, remote_port);
Udp.write(packetBuffer, 10);
Udp.endPacket();
#endif
#if defined(USE_ILI9341_T3) || defined(USE_ILI9341_T3N)
// tft.fillRect(0, 0, tft.width(), 8, ILI9341_BLACK);
tft.setCursor(10, (tft.height()*3)/4);
tft.print(loop_count);
#endif
Serial.println(loop_count);
loop_count++;
delay(100);
}