--- title: FabLab ressources tags: arduino, fablab robots: noindex, nofollow author: Julien Noyer --- # Ressources - [Boutique Hackspark](https://hackspark.fr/fr/) - [Outil de prototypage](https://www.tinkercad.com) ## LED + bouton ```java /* This program blinks pin 13 of the Arduino (the built-in LED) */ int redLed = 8; int myButton = 2; void setup() { Serial.begin(9600); pinMode(redLed, OUTPUT); pinMode(myButton, INPUT); } void loop() { Serial.println(digitalRead(myButton)); digitalRead(myButton) == 0 ? digitalWrite(redLed, LOW) : digitalWrite(redLed, HIGH); delay(10); // Wait for 1000 millisecond(s) } ``` ```javascript= /* Import des bibliothèques */ #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> /**/ /* Déclaration */ /* Server */ IPAddress apIP(192, 168, 0, 39); ESP8266WebServer server(80); /* Réseeau */ char* ssid = "DWShotspot"; char* password = "kindnetwork"; /* Composants */ const int greenLed = D7; const int yellowLed = D8; /**/ /* Pages Web */ /* Accueil */ char homePage[] PROGMEM = R"=====( <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>The Wemos Website</title> <style> *{margin:0;padding:0;box-sizing:border-box} html{font-size:62.5%}body{font-family:sans-serif;font-size:1.6rem} footer,header{text-align:center;padding:2rem;position:fixed;left:0;width:100%;background-color:#eee} header{top:0} h1{text-transform:uppercase} h1 span{font-size:.5em;font-weight:100;text-transform:none;margin-bottom:1rem;display:block} nav li{display:inline-block;margin:0 1rem} nav a{font-size:1.1rem;font-weight:900;text-transform:uppercase;text-decoration:none;color:#fff;padding:.5rem;background-color:#000} main{max-width:90rem;margin:auto;display:flex;width:100vw;height:100vh} section{margin:auto} button{font-size:2.5rem;font-weight:900;text-transform:uppercase;width:20rem;height:20rem;background:#9acd32;border-radius:50%;box-shadow:0 0 1rem rgba(0,0,0,.1);border:1rem solid #fff;margin:0 2rem} button:last-of-type{background-color:#ff0} button span{margin-top:1rem;display:inline-block} button b{font-size:1.5rem;font-weight:100;display:block} footer{bottom:0} </style> </head> <body> <header> <h1>The Wemos Website <span>Play with network and ESP8266 microcontroller</span></h1> </header> <main> <section> <button type="button" data-color="green"><span>Green LED <b>Off</b></span></button> <button type="button" data-color="yellow"><span>Yellow LED <b>Off</b></span></button> </section> </main> <footer> <p>Under WTFPL - 2019 by Julien Noyer</p> </footer> <script> document.addEventListener('DOMContentLoaded', () => { for( let button of document.querySelectorAll('button') ){ button.addEventListener('click', () => { fetch(`toggle/${button.getAttribute('data-color')}`) .then(wemosResponse => wemosResponse.json()) .then( jsonResponse => { console.log(jsonResponse); jsonResponse.msg === "on" ? button.innerHTML = `<span>${button.getAttribute('data-color')} LED<b>on</b></span>` : button.innerHTML = `<span>${button.getAttribute('data-color')} LED<b>Off</b></span>` }) .catch( jsonResponse => { console.log(jsonResponse) }) }) } }) </script> </body> </html> )====="; /**/ /* Fonctions des routes du serveur */ // Route : index void handleRoot() { Serial.println("homepage"); server.send(200, "text/html", homePage); } void toggleGreenLed(){ digitalWrite(greenLed,!digitalRead(greenLed)); String led_state = digitalRead(greenLed) ? "on" : "off"; server.send(200, "application/json", "{ \"msg\": \"" + led_state + "\" }"); } void toggleYellowLed(){ digitalWrite(yellowLed,!digitalRead(yellowLed)); String led_state = digitalRead(yellowLed) ? "on" : "off"; server.send(200, "application/json", "{ \"msg\": \"" + led_state + "\" }"); } /**/ /**/ /* Fonction de configuration */ void setup(){ /* Composants */ pinMode(greenLed, OUTPUT); pinMode(yellowLed, OUTPUT); digitalWrite(greenLed, LOW); digitalWrite(yellowLed, LOW); // Défnition de la vitesse de communication avec la WeMos Serial.begin(115200); Serial.println(""); // Configuration du mode Access Point WiFi.mode(WIFI_AP); // Création du réseau WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); // Static IP WiFi.softAP(ssid, password); // Affichage des identifiants de connexion Serial.println(ssid); Serial.println(password); // Définition de l'adresse IP de la WeMos IPAddress myIP = WiFi.softAPIP(); Serial.print("HotSpot IP: "); Serial.println(myIP); // 2couter les routes server.on("/", handleRoot); server.on("/toggle/green", toggleGreenLed); server.on("/toggle/yellow", toggleYellowLed); // Lancer le server server.begin(); Serial.println("Serveur HTTP démarré"); } /**/ /* Fonction principale du microcontrolleur */ void loop(){ server.handleClient(); } /**//* Import des bibliothèques */ #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> /**/ /* Déclaration */ /* Server */ IPAddress apIP(192, 168, 0, 39); ESP8266WebServer server(80); /* Réseeau */ char* ssid = "DWShotspot"; char* password = "kindnetwork"; /* Composants */ const int greenLed = D7; const int yellowLed = D8; /**/ /* Pages Web */ /* Accueil */ char homePage[] PROGMEM = R"=====( <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>The Wemos Website</title> <style> *{margin:0;padding:0;box-sizing:border-box} html{font-size:62.5%}body{font-family:sans-serif;font-size:1.6rem} footer,header{text-align:center;padding:2rem;position:fixed;left:0;width:100%;background-color:#eee} header{top:0} h1{text-transform:uppercase} h1 span{font-size:.5em;font-weight:100;text-transform:none;margin-bottom:1rem;display:block} nav li{display:inline-block;margin:0 1rem} nav a{font-size:1.1rem;font-weight:900;text-transform:uppercase;text-decoration:none;color:#fff;padding:.5rem;background-color:#000} main{max-width:90rem;margin:auto;display:flex;width:100vw;height:100vh} section{margin:auto} button{font-size:2.5rem;font-weight:900;text-transform:uppercase;width:20rem;height:20rem;background:#9acd32;border-radius:50%;box-shadow:0 0 1rem rgba(0,0,0,.1);border:1rem solid #fff;margin:0 2rem} button:last-of-type{background-color:#ff0} button span{margin-top:1rem;display:inline-block} button b{font-size:1.5rem;font-weight:100;display:block} footer{bottom:0} </style> </head> <body> <header> <h1>The Wemos Website <span>Play with network and ESP8266 microcontroller</span></h1> </header> <main> <section> <button type="button" data-color="green"><span>Green LED <b>Off</b></span></button> <button type="button" data-color="yellow"><span>Yellow LED <b>Off</b></span></button> </section> </main> <footer> <p>Under WTFPL - 2019 by Julien Noyer</p> </footer> <script> document.addEventListener('DOMContentLoaded', () => { for( let button of document.querySelectorAll('button') ){ button.addEventListener('click', () => { fetch(`toggle/${button.getAttribute('data-color')}`) .then(wemosResponse => wemosResponse.json()) .then( jsonResponse => { console.log(jsonResponse); jsonResponse.msg === "on" ? button.innerHTML = `<span>${button.getAttribute('data-color')} LED<b>on</b></span>` : button.innerHTML = `<span>${button.getAttribute('data-color')} LED<b>Off</b></span>` }) .catch( jsonResponse => { console.log(jsonResponse) }) }) } }) </script> </body> </html> )====="; /**/ /* Fonctions des routes du serveur */ // Route : index void handleRoot() { Serial.println("homepage"); server.send(200, "text/html", homePage); } void toggleGreenLed(){ digitalWrite(greenLed,!digitalRead(greenLed)); String led_state = digitalRead(greenLed) ? "on" : "off"; server.send(200, "application/json", "{ \"msg\": \"" + led_state + "\" }"); } void toggleYellowLed(){ digitalWrite(yellowLed,!digitalRead(yellowLed)); String led_state = digitalRead(yellowLed) ? "on" : "off"; server.send(200, "application/json", "{ \"msg\": \"" + led_state + "\" }"); } /**/ /**/ /* Fonction de configuration */ void setup(){ /* Composants */ pinMode(greenLed, OUTPUT); pinMode(yellowLed, OUTPUT); digitalWrite(greenLed, LOW); digitalWrite(yellowLed, LOW); // Défnition de la vitesse de communication avec la WeMos Serial.begin(115200); Serial.println(""); // Configuration du mode Access Point WiFi.mode(WIFI_AP); // Création du réseau WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); // Static IP WiFi.softAP(ssid, password); // Affichage des identifiants de connexion Serial.println(ssid); Serial.println(password); // Définition de l'adresse IP de la WeMos IPAddress myIP = WiFi.softAPIP(); Serial.print("HotSpot IP: "); Serial.println(myIP); // 2couter les routes server.on("/", handleRoot); server.on("/toggle/green", toggleGreenLed); server.on("/toggle/yellow", toggleYellowLed); // Lancer le server server.begin(); Serial.println("Serveur HTTP démarré"); } /**/ /* Fonction principale du microcontrolleur */ void loop(){ server.handleClient(); } /**/ ```