Justinberger

Buzzer

Mar 22nd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.35 KB | None | 0 0
  1. //https://www.arduinoplatform.com/arduino-project/create-a-touch-button-with-copper-aluminum-foil/
  2. //https://www.instructables.com/id/To-Use-WIZ550io-in-Arduino-Platform-Arduino-UNO/
  3. //https://startingelectronics.org/tutorials/arduino/ethernet-shield-web-server-tutorial/CSS-introduction/
  4.      
  5. #include <CapacitiveSensor.h>
  6. #include <SPI.h>
  7. #include <Ethernet2.h>
  8.  
  9. // Enter a MAC address and IP address for your controller below.
  10. // The IP address will be dependent on your local network:
  11. byte mac[] = {
  12.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  13. };
  14. IPAddress ip(192, 168, 1, 3);
  15.  
  16. // Initialize the Ethernet server library
  17. // with the IP address and port you want to use
  18. // (port 80 is default for HTTP):
  19. EthernetServer server(80);
  20.    
  21.     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
  22.     CapacitiveSensor   cs_8_3 = CapacitiveSensor(8, 3);
  23.     CapacitiveSensor   cs_8_4 = CapacitiveSensor(8, 4);  
  24.     int treshold = 10000; // the minimum value for turning the LED on
  25.     int ledPin1 = A3;
  26.     int ledPin2 = A1;
  27.     int ledPin3 = A2;
  28.     int reponse = 5000;
  29.     int compteur;
  30.     int valeur;
  31.     char score_equipe1;
  32.     char score_equipe2;
  33.     char score_equipe3;
  34.     char score_equipe4;
  35.     char score_equipe5;
  36.     char score_equipe6;
  37.     unsigned long time = 0;
  38.     String resultat = "TEST";
  39.  
  40.    
  41. void setup() {
  42.   pinMode(ledPin1, OUTPUT);
  43.   pinMode(ledPin2, OUTPUT);
  44.   pinMode(ledPin3, OUTPUT);
  45.   // Open serial communications and wait for port to open:
  46.   Serial.begin(9600);
  47.   compteur=1; // initialisation de compteur
  48.   while (!Serial) {
  49.     ; // wait for serial port to connect. Needed for Leonardo only
  50.   }
  51.  
  52.   // start the Ethernet connection and the server:
  53.   Ethernet.begin(mac, ip);
  54.   server.begin();
  55.   Serial.print("server is at ");
  56.   Serial.println(Ethernet.localIP());
  57. }
  58.  
  59. void loop() {
  60.  
  61.       Serial.println((String)"Compteur :"+compteur); //affiche la valeur de compteur
  62.       compteur=compteur+1; //on ajoute 1 à compteur      
  63.       if (compteur==1){
  64. //      delay(reponse);
  65.       while(millis() < time + reponse){
  66.           //wait approx. [reponse] ms
  67.           }
  68.       }
  69.     long start = millis();
  70.     long sensorValue1 =  cs_8_2.capacitiveSensor(30);
  71.     long sensorValue2 =  cs_8_3.capacitiveSensor(30);
  72.     long sensorValue3 =  cs_8_4.capacitiveSensor(30);
  73.     time = millis();
  74.  
  75. Serial.println(sensorValue1);    
  76. Serial.println(sensorValue2);      
  77. Serial.println(sensorValue3);
  78.  
  79.  
  80. //Serveur WEB
  81.   // listen for incoming clients
  82.   EthernetClient client = server.available();
  83.   if (client) {
  84. //    Serial.println("new client");
  85.     // an http request ends with a blank line
  86.     boolean currentLineIsBlank = true;
  87.     while (client.connected()) {
  88.       if (client.available()) {
  89.         char c = client.read();
  90. //        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
  91.         if (c == '\n' && currentLineIsBlank) {
  92.           // send a standard http response header
  93.           client.println("HTTP/1.1 200 OK");
  94.           client.println("Content-Type: text/html");
  95.           client.println("Connection: close");  // the connection will be closed after completion of the response
  96.           client.println("Refresh: 0.01");  // refresh the page automatically every 0.01 sec
  97.           client.println();
  98.           client.println("<!DOCTYPE HTML>");
  99.           client.println("<html>");
  100.           client.println("    <head>");
  101.           client.println("        <title>Blind test</title>");
  102.           client.println("        <style type=text/css>");
  103.           client.println("            h1 {font-family: courier, courier-new, serif;");
  104.           client.println("                font-size: 20pt;");
  105.           client.println("                color: blue;");
  106.           client.println("                border-bottom: 2px solid blue;}");
  107.           client.println("            p {font-family: arial, verdana, sans-serif;");
  108.           client.println("                font-size: 12pt;");
  109.           client.println("                color: #6B6BD7;}");
  110.           client.println("            p1 {font-family: arial, verdana, sans-serif;");
  111.           client.println("                font-size: 20pt;");
  112.           client.println("                color: #00FF00;");
  113.           client.println("                font-weight: bold;}");//Style Gras
  114.           client.println("            table,");
  115.           client.println("             td { border: 1px solid #333;}");
  116.           client.println("            thead,");
  117.           client.println("              tfoot {background-color: #333;");
  118.           client.println("                color: #fff;}");
  119.           client.println("        </style>");
  120.           client.println("    </head>");
  121.           client.println("    <body>");
  122.           client.println("        <h1>Blind Test</h1>");
  123.          
  124.  
  125. //___________________________________________________________________JOUEUR 1______________//
  126.           if (sensorValue2 > treshold) {
  127.           digitalWrite(ledPin2, HIGH);
  128.           compteur = 0;
  129.           String resultat = "JOUEUR 2";
  130.           client.println((String)"        <p1>"+resultat+"</p1>");
  131.           }
  132. //___________________________________________________________________JOUEUR 1______________//
  133.           else if (sensorValue3 > treshold) {
  134.           digitalWrite(ledPin3, HIGH);
  135.           compteur = 0;
  136.           String resultat = "JOUEUR 3";
  137.           client.println((String)"        <p1>"+resultat+"</p1>");
  138.           }
  139.  
  140.           else {
  141.           digitalWrite(ledPin2, LOW);
  142.           digitalWrite(ledPin3, LOW);
  143.           }
  144.  
  145. //___________________________________________________________________Calcul de la valeur de la question______________//  
  146.          
  147.          
  148.          if (sensorValue1 > treshold) {
  149.           valeur=valeur+1;
  150.            if (valeur>5){
  151.             valeur=0;
  152.             }
  153.           digitalWrite(ledPin1, HIGH);
  154.           }
  155.           else {
  156.           digitalWrite(ledPin1, LOW);
  157.           }
  158.  
  159.           client.println((String)"        <p1>Question a</p1>");
  160.           if (valeur>1) {
  161.           client.println((String)"        <p1>"+valeur+" points</p1>");
  162.           }
  163.           else {
  164.           client.println((String)"        <p1>"+valeur+" point</p1>");
  165.           }
  166.          
  167. //___________________________________________________________________Affichage du score______________//  
  168.           client.println("<table>");
  169.           client.println("    <thead>");
  170.           client.println("        <tr>");
  171.           client.println("            <th colspan=6>Score</th>");
  172.           client.println("        </tr>");
  173.           client.println("    </thead>");
  174.           client.println("    <tbody>");
  175.           client.println("        <tr>");
  176.           client.println("            <td>Equipe 1</td>");
  177.           client.println("            <td>Equipe 2</td>");
  178.           client.println("            <td>Equipe 3</td>");
  179.           client.println("            <td>Equipe 4</td>");
  180.           client.println("            <td>Equipe 5</td>");
  181.           client.println("            <td>Equipe 6</td>");
  182.           client.println("        </tr>");
  183.           client.println("        <tr>");
  184.           client.println("            <td>Equipe 2</td>");
  185.           client.println("            <td>Equipe 3</td>");
  186.           client.println("            <td>Equipe 4</td>");
  187.           client.println("            <td>Equipe 5</td>");
  188.           client.println("            <td>Equipe 6</td>");
  189.           client.println("        </tr>");
  190.           client.println("    </tbody>");
  191.           client.println("</table>");
  192.  
  193.  
  194.           client.println("    </body>");
  195.           client.println("</html>");
  196.           break;
  197.         }
  198.         if (c == '\n') {
  199.           // you're starting a new line
  200.           currentLineIsBlank = true;
  201.         }
  202.         else if (c != '\r') {
  203.           // you've gotten a character on the current line
  204.           currentLineIsBlank = false;
  205.         }
  206.       }
  207.     }
  208.     // give the web browser time to receive the data
  209.     delay(1);
  210.     // close the connection:
  211.     client.stop();
  212.     Serial.println("client disconnected");
  213.   }
  214.  
  215.    
  216.       Serial.print("\n");
  217. }
Add Comment
Please, Sign In to add comment