Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.arduinoplatform.com/arduino-project/create-a-touch-button-with-copper-aluminum-foil/
- //https://www.instructables.com/id/To-Use-WIZ550io-in-Arduino-Platform-Arduino-UNO/
- //https://startingelectronics.org/tutorials/arduino/ethernet-shield-web-server-tutorial/CSS-introduction/
- #include <CapacitiveSensor.h>
- #include <SPI.h>
- #include <Ethernet2.h>
- // Enter a MAC address and IP address for your controller below.
- // The IP address will be dependent on your local network:
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- IPAddress ip(192, 168, 1, 3);
- // Initialize the Ethernet server library
- // with the IP address and port you want to use
- // (port 80 is default for HTTP):
- EthernetServer server(80);
- CapacitiveSensor cs_8_2 = CapacitiveSensor(8, 2); // 330-ohmn resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
- CapacitiveSensor cs_8_3 = CapacitiveSensor(8, 3);
- CapacitiveSensor cs_8_4 = CapacitiveSensor(8, 4);
- int treshold = 10000; // the minimum value for turning the LED on
- int ledPin1 = A3;
- int ledPin2 = A1;
- int ledPin3 = A2;
- int reponse = 5000;
- int compteur;
- int valeur;
- char score_equipe1;
- char score_equipe2;
- char score_equipe3;
- char score_equipe4;
- char score_equipe5;
- char score_equipe6;
- unsigned long time = 0;
- String resultat = "TEST";
- void setup() {
- pinMode(ledPin1, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- pinMode(ledPin3, OUTPUT);
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- compteur=1; // initialisation de compteur
- while (!Serial) {
- ; // wait for serial port to connect. Needed for Leonardo only
- }
- // start the Ethernet connection and the server:
- Ethernet.begin(mac, ip);
- server.begin();
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- }
- void loop() {
- Serial.println((String)"Compteur :"+compteur); //affiche la valeur de compteur
- compteur=compteur+1; //on ajoute 1 à compteur
- if (compteur==1){
- // delay(reponse);
- while(millis() < time + reponse){
- //wait approx. [reponse] ms
- }
- }
- long start = millis();
- long sensorValue1 = cs_8_2.capacitiveSensor(30);
- long sensorValue2 = cs_8_3.capacitiveSensor(30);
- long sensorValue3 = cs_8_4.capacitiveSensor(30);
- time = millis();
- Serial.println(sensorValue1);
- Serial.println(sensorValue2);
- Serial.println(sensorValue3);
- //Serveur WEB
- // 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); //permet d'afficher tous les paramètres du client qui se connectes 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("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close"); // the connection will be closed after completion of the response
- client.println("Refresh: 0.01"); // refresh the page automatically every 0.01 sec
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println(" <head>");
- client.println(" <title>Blind test</title>");
- client.println(" <style type=text/css>");
- client.println(" h1 {font-family: courier, courier-new, serif;");
- client.println(" font-size: 20pt;");
- client.println(" color: blue;");
- client.println(" border-bottom: 2px solid blue;}");
- client.println(" p {font-family: arial, verdana, sans-serif;");
- client.println(" font-size: 12pt;");
- client.println(" color: #6B6BD7;}");
- client.println(" p1 {font-family: arial, verdana, sans-serif;");
- client.println(" font-size: 20pt;");
- client.println(" color: #00FF00;");
- client.println(" font-weight: bold;}");//Style Gras
- client.println(" table,");
- client.println(" td { border: 1px solid #333;}");
- client.println(" thead,");
- client.println(" tfoot {background-color: #333;");
- client.println(" color: #fff;}");
- client.println(" </style>");
- client.println(" </head>");
- client.println(" <body>");
- client.println(" <h1>Blind Test</h1>");
- //___________________________________________________________________JOUEUR 1______________//
- if (sensorValue2 > treshold) {
- digitalWrite(ledPin2, HIGH);
- compteur = 0;
- String resultat = "JOUEUR 2";
- client.println((String)" <p1>"+resultat+"</p1>");
- }
- //___________________________________________________________________JOUEUR 1______________//
- else if (sensorValue3 > treshold) {
- digitalWrite(ledPin3, HIGH);
- compteur = 0;
- String resultat = "JOUEUR 3";
- client.println((String)" <p1>"+resultat+"</p1>");
- }
- else {
- digitalWrite(ledPin2, LOW);
- digitalWrite(ledPin3, LOW);
- }
- //___________________________________________________________________Calcul de la valeur de la question______________//
- if (sensorValue1 > treshold) {
- valeur=valeur+1;
- if (valeur>5){
- valeur=0;
- }
- digitalWrite(ledPin1, HIGH);
- }
- else {
- digitalWrite(ledPin1, LOW);
- }
- client.println((String)" <p1>Question a</p1>");
- if (valeur>1) {
- client.println((String)" <p1>"+valeur+" points</p1>");
- }
- else {
- client.println((String)" <p1>"+valeur+" point</p1>");
- }
- //___________________________________________________________________Affichage du score______________//
- client.println("<table>");
- client.println(" <thead>");
- client.println(" <tr>");
- client.println(" <th colspan=6>Score</th>");
- client.println(" </tr>");
- client.println(" </thead>");
- client.println(" <tbody>");
- client.println(" <tr>");
- client.println(" <td>Equipe 1</td>");
- client.println(" <td>Equipe 2</td>");
- client.println(" <td>Equipe 3</td>");
- client.println(" <td>Equipe 4</td>");
- client.println(" <td>Equipe 5</td>");
- client.println(" <td>Equipe 6</td>");
- client.println(" </tr>");
- client.println(" <tr>");
- client.println(" <td>Equipe 2</td>");
- client.println(" <td>Equipe 3</td>");
- client.println(" <td>Equipe 4</td>");
- client.println(" <td>Equipe 5</td>");
- client.println(" <td>Equipe 6</td>");
- client.println(" </tr>");
- client.println(" </tbody>");
- client.println("</table>");
- client.println(" </body>");
- client.println("</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");
- }
- Serial.print("\n");
- }
Add Comment
Please, Sign In to add comment