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
| #include <SPI.h>
// DALLE TACTILE ************************************************************************************************************************************************
// Calibration à faire avec 003_TFT_Touch_Calibrate_OK
#include "URTouch.h"
#define t_IRQ 5
#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);
// ECRAN TFT ****************************************************************************************************************************************************
#include <PDQ_GFX.h>
#include "PDQ_ILI9341_config.h" // C'est dans le fichier PDQ_ILI9341_config.h qu'on définit les broches CS, DC et RST :
//#define ILI9341_CS_PIN 0 // <= /CS pin (chip-select, LOW to get attention of ILI9341, HIGH and it ignores SPI bus)
//#define ILI9341_DC_PIN 9 // <= DC pin (1=data or 0=command indicator line) also called RS
//#define ILI9341_RST_PIN 8 // <= RST pin (optional)
#include <PDQ_ILI9341.h> // PDQ: Hardware-specific driver library
PDQ_ILI9341 tft;
#define TFT_PWM_LED 6 // Un transistor PNP permet de piloter le rétroéclairage
// ETHERNET *****************************************************************************************************************************************************
#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.
byte mac[] = {
0xA8, 0x61, 0x0A, 0xAE, 0x75, 0xCA //Voir étiquette collée sous le Shield
};
IPAddress ip(192, 168, 123, 177); //Choisir une IP fixe compatible avec le réseau local ou bien utiliser DHCP
EthernetServer server(80);
// VARIABLES GLOBALES *******************************************************************************************************************************************
char Buffer_DispXY[15];
int sensorReading;
int dernierx;
int derniery;
// SETUP ********************************************************************************************************************************************************
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);
// 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();
}
// LOOP *********************************************************************************************************************************************************
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");
}
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(10);
tft.setCursor(55, 5);
tft.print(Buffer_DispXY);
tft.setCursor(55, 25);
tft.print(Buffer_DispXY);
tft.setCursor(55, 45);
tft.print(Buffer_DispXY);
tft.setCursor(55, 65);
tft.print(Buffer_DispXY);
tft.setCursor(55, 85);
tft.print(Buffer_DispXY);
tft.setCursor(55, 105);
tft.print(Buffer_DispXY);
tft.setCursor(55, 125);
tft.print(Buffer_DispXY);
tft.setCursor(55, 145);
tft.print(Buffer_DispXY);
tft.setCursor(55, 165);
tft.print(Buffer_DispXY);
tft.setCursor(55, 185);
tft.print(Buffer_DispXY);
tft.setCursor(55, 205);
tft.print(Buffer_DispXY);
tft.setCursor(55, 225);
tft.print(Buffer_DispXY);
tft.setCursor(55, 245);
tft.print(Buffer_DispXY);
tft.setCursor(55, 265);
tft.print(Buffer_DispXY);
tft.setCursor(55, 285);
tft.print(Buffer_DispXY);
tft.setCursor(55, 305);
tft.print(Buffer_DispXY);
tft.setCursor(55, 325);
tft.print(Buffer_DispXY);
retro=y-10;
if (retro<0) {retro=0;}
if (retro>255) {retro=255;}
analogWrite(TFT_PWM_LED,retro);
//delay(10);
}
}
} |
Partager