1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
| #include <SPI.h>
#include <Ethernet.h>
// Ethernet Shield 2 : communicates with both the W5500 and SD card using the SPI bus (through the ICSP header).
// This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega.
// On both boards, pin 10 is used to select the W5500 and pin 4 for the SD card. These pins cannot be used for general I/O.
// On the Mega, the hardware SS pin, 53, is not used to select either the W5500 or the SD card, but it must be kept as an output or the SPI interface won't work.
#include "Adafruit_GFX.h" // Trouvé et ajouté via le menu Outil / Gérer les bibliothèques
#include "Adafruit_ILI9341.h" // Trouvé et ajouté via le menu Outil / Gérer les bibliothèques
#include "URTouch.h" // Ajouté au format ZIP
//On définit les broches pour la partie affichage
#define TFT_CLK 13
#define TFT_MISO 12
#define TFT_MOSI 11
//#define TFT_CS 10
#define TFT_CS 0 // On change juste cette broche pour piloter aussi le module Ethernet avec le bus SPI
#define TFT_DC 9
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#define TFT_PWM_LED 6 // Un transistor PNP permet de piloter le rétroéclairage
// Il est possible d'ajuster le niveau de rétroéclairage en fonction de la luminosité ambiante grâce à une photodiode sur une entrée analogique
// On peut réduire et éteindre le rétroéclairage après une période d'inactivité de la dalle tactile
// Et réactiver le rétroéclairage en cas de notification
//On définit les broches pour la partie tactile
#define t_IRQ 5
//#define t_MISO 4
#define t_MISO 7 // La broche 4 est utilisée pour le lecteur SD de l'ethernet Shield
#define t_MOSI 3
#define t_CS 2
#define t_SCK 1
URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xA8, 0x61, 0x0A, 0xAE, 0x75, 0xCA
};
IPAddress ip(192, 168, 123, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
char Buffer_DispXY[15];
int sensorReading;
int dernierx;
int derniery;
void setup() {
int radius = 4;
dernierx=-1;
derniery=-1;
analogWrite(TFT_PWM_LED,128);
tft.begin();
tft.setRotation(0);
ts.InitTouch(PORTRAIT);
ts.setPrecision(PREC_EXTREME);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
tft.setTextSize(2);
tft.fillCircle(10, 10, radius, ILI9341_YELLOW);
tft.fillCircle(10, 310, radius, ILI9341_YELLOW);
tft.fillCircle(230, 310, radius, ILI9341_YELLOW);
tft.fillCircle(230, 10, radius, ILI9341_YELLOW);
tft.fillCircle(120, 160, radius, ILI9341_YELLOW);
sensorReading = 555;
snprintf_P(Buffer_DispXY, sizeof(Buffer_DispXY), PSTR("A = %d"), sensorReading);
tft.setCursor(55, 5);
tft.print(Buffer_DispXY);
/*
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet WebServer Example");
*/
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
//Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
//Serial.println("Ethernet cable is not connected.");
}
// start the server
server.begin();
//Serial.print("server is at ");
//Serial.println(Ethernet.localIP());
}
void loop() {
int retro;
int x, y;
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
//Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
//Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println(F("Connection: close")); // the connection will be closed after completion of the response
client.println(F("Refresh: 5")); // refresh the page automatically every 5 sec
client.println();
client.println(F("<!DOCTYPE HTML>"));
client.println(F("<html>"));
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
sensorReading = analogRead(analogChannel);
client.print(F("analog input "));
client.print(analogChannel);
client.print(F(" is "));
client.print(sensorReading);
client.println(F("<br />"));
}
client.print(F("TFT X="));
client.print(dernierx);
client.print(F(" Y="));
client.print(derniery);
client.println(F("</html>"));
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
//Serial.println("client disconnected");
// Affichage sur l'écran TFT - ne fonctionne pas
snprintf_P(Buffer_DispXY, sizeof(Buffer_DispXY), PSTR("A = %d"), sensorReading);
delay(1);
tft.setCursor(55, 5);
tft.print(Buffer_DispXY);
delay(1);
}
while (ts.dataAvailable())
{
ts.read();
x = ts.getX();
y = ts.getY();
if ((x != -1) && (y != -1))
{
dernierx=x;
derniery=y;
snprintf_P(Buffer_DispXY, sizeof(Buffer_DispXY), PSTR("X=%3d Y=%3d"), x, y);
delay(1);
tft.setCursor(55, 5);
tft.print(Buffer_DispXY);
delay(1);
retro=y-10;
if (retro<0) {retro=0;}
if (retro>255) {retro=255;}
analogWrite(TFT_PWM_LED,retro);
}
}
} |
Partager