Une interface graphique pour afficher la température et l’humidité ?

Avec ce tuto vous allez apprendre comment recevoir par le wifi les données de température et d’humidité d’un capteur DHT22. De plus, ces données seront affichées graphiquement sur une page WEB.

Vous trouverez ci-dessous le lien vous permettant de télécharger les différents programmes utilisés dans la vidéo :

https://drive.google.com/drive/u/2/folders/1m-ObuIALDxmKUc33AwUFBi9nqxsAVX0h

la vidéo :

Projet domotique: la caméra wifi.

Marc est un des spécialistes du Fablab dans le domaine de la domotique, nous lui devons déjà le système de pilotage de volets roulant. Il s’attaque maintenant à la vidéosurveillance avec son projet de caméra wifi .

Basé sur un ESP32-CAM que l’on trouve à moins de 6€, la caméra est intégrable dans notre Box Domotique.

Quelques images du projet:

Modélisation du support de caméra dans Fusion360.
Prévisualisation du support de caméra équipé de l’ESP32-CAM
Les pièces imprimées 3D et la cloche en tube plexiglass
Le montage terminé evec l’ESP32-CAM

Les STL et le code source seront bientôt disponible sur notre drive.

Phares d’iroise

Marc et Jean-Yves ont réaliser des modélisations de phares :
Le four, le Stiff, le Créach, la Jument et Kermorvan sont réalisés.
Ces modélisations 3D doivent clignoter selon leur signature lumineuse,
par ex le Four possède 5 éclats toutes les 15s.

Ainsi, conformément à notre devise, CONCEVOIR – MODÉLISER – FABRIQUER
voici les différentes étapes de ce projet en images :

Vue du fichier stl du phare du Four réalisé avec un logiciel de conception 3D avant son export Gcode
pour l’impression 3D
Programmation de l’Attiny 85 à l’aide de la carte Arduino Uno en mode ISP
//Programme clignotements led en fonction de la valeur analogique
//d'un pont diviseur. © Fablab Iroise

#include "tinysnore.h" // Include TinySnore Library

#define pinLed 0
#define RPin A1

int RValue = 0;

void setup() {
  // put your setup code here, to run once:

  pinMode(pinLed, OUTPUT);
  RValue = analogRead(RPin);


}
void loop() {

  if (RValue < 100) { // Four 5 eclats /15s

    digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
        digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
        digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
        digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
        digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(10000);//delay(2000);
  }
  if (RValue > 100 && RValue < 200) { // St-Mathieu 1 eclats /15s
         digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(14500);//delay(2000);
  }
   if (RValue > 200 && RValue < 300) { // Ile Vierge/Kermorvan 1 eclats /5s Pierres noire idem Rouge
         digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(4500);//delay(2000);
  }
   if (RValue > 300 && RValue < 400) { // Le Créach 2 eclats /10s Pierres noire idem Rouge
          digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
         digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(8500);//delay(2000);
  }
  if (RValue > 500 && RValue < 600) { // Le Stiff 2 eclats /20s  Rouge
          digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
         digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(18500);//delay(2000);
  }
   if (RValue > 700 && RValue < 800) { // Nividic 9 scintillements /10s  Blanc
          digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
           digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
           digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
           digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
           digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
           digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
           digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
           digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(250);//delay(2000);
         digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(5000);//delay(2000);
  }
  if (RValue > 800 && RValue < 900) { // La Jument 3 eclats /15s  Blanc
          digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
    digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(1000);//delay(2000);
         digitalWrite(pinLed, HIGH);   // turn the LED on (HIGH is the voltage level)
    snore(250);                       // wait for a half second
    digitalWrite(pinLed, LOW);    // turn the LED off by making the voltage LOW
    snore(12
    500);//delay(2000);
  }
}
Test du montage sur breadboard : alimentation 3V led + résistance 10Ω, 2 résistances 100 kΩ et 10 kΩ pour le pont diviseur.
Utilisation de la bibliothèque tinysnore pour n’activer la consommation que lors des flashs lumineux
Recherche des valeurs de ponts diviseurs avec les valeurs de résistance disponibles
Conception sur Kicad du circuit
Vue du circuit
Réception des circuits imprimés fabriqués
Montage des composants soudés, la pile est au verso et restera accessible sous le phare

Lampe chêne-leds

Bandeau leds 5V, interrupteur sensitif et planche de chêne …

Un petit projet tout simple : alimentation USB, bandeau leds 5V et un interrupteur sensitif lumineux, une résistance 1kΩ, un transistor NPN TIP31. Un total de 4 euros pour l’électronique et une chute de bois !!!
L’interrupteur envoi un signal 5V en cas de contact, donc utilisation d’un transistor NPN TIP31 pour effectuer le contact GND du bandeau led :

Mais où est la poussière ? eh bien comme souvent sous le tapis :

Le CervaCapsulator du Science Hack Day 19

Lors du SHD 2019, a été réalisé le CervaCapsulator Grand Ouest, (article wiki des fabriques du Ponant) : voici les images et les fichiers à télécharger pour vos amis cervacapsulophiles !!!
Fichier pdf de la carte et fichier svg pour la découpe laser (80×100 cm)
Pour une laser plus petite chaque département est séparé dans un calque.

La carte des emplacements
Le CervaCapsulator Grand Ouest (photo Antony)
Début de remplissage pour le CervaCapsulator 29 (photo Antony)

Voici le lien pour télécharger les fichiers :
CervaCapsulator Grand Ouest

Box domotique V1 – Partie 1

Besoin :

Création d’une box permettant d’interagir avec différents objets connectés.
La box doit être :
– Multi-protocoles (Wifi, GPIO, Radio 433 Mhz et 2.4 Ghz, …)
– La plus libre et la moins couteuse possible

Le materiel :

  • Un raspberry
  • Une carte SD
  • Un module émetteur 433 Mhz

Les étapes :

  • Installer Rasbian lite sans clavier ni écran (SSH)
  • Paramétrer Rasbian
  • Installer Node-red
  • Piloter les GPIO avec Node-red
  • Prises Chacon

Installer Rasbian sans clavier ni écran (en mode SSH)

– On télécharge l’image du système d’exploitation du raspberry Rasbian lite
– On copie l’image sur la carte SD grâce au logiciel Etcher.
– Afin d’activer le protocole SSH pour le premier démarage du raspberry, on crée un fichier vide et sans extension (ex: .txt) nomé ssh dans le répertoire /BOOT de la carte SD.
– On raccorde le pi en ethernet sur sa box et on l’alimente.

Paramétrer Rasbian

– On  récupère l’adresse IP du raspberry via l’interface de gestion de sa box opérateur.
– Avec le logiciel client ssh Putty on se connecte en SSH sur le raspberry. (id pi/raspberry)
– Pour paramétrer le raspberry on tape la commande suivante

sudo raspi-config

raspi-config
On en profite pour:

Choix 1 : modifier le mot de passe par défaut #sécu
Choix 4 : on paramètre le langage (fr_FR.UTF-8 UTF-8>) et la Timezone
Choix 5 : on active le remote GPIO
Choix 7 : Expand Filesystem

On paramètre l’interface Ethernet en @IP fixe (tuto sur domo-blog.fr)

sudo nano /etc/dhcpcd.conf

ip-fixe
On reboot le raspbery:

sudo reboot

Installer Node-Red

bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

A l’issue de l’installation (~ 30 min) on tape la commande suivante pour que node-red démarre automatiquement au démarrage du raspberry :

sudo systemctl enable nodered.service

On peut maintenant ouvrir Node-red dans le navigateur à cette adresse :
http://192.168.1.100:1880

node-red
On en profite pour installer le pacquet node-red-dashboard via le Manage palette, il nous servira à créer l’interface graphique de notre projet.

Piloter les GPIO avec Node-Red

Super tuto + exemple de mangeoire et sonnette connectées eduscol.education.fr.

 

Prise CHACON DIO

Nous allons commander ces prises grâce à un émetteur 433 Mhz. Ces prises sont disponible chez Leroy Merlin pour – de 30€

lot-de-3-prises-telecommandables-interieure-dio

Montage:

Untitled Sketch_bb2

sources:
https://flows.nodered.org/flow/e33d31301c522dab4be2c68eb55c5fc5

cd /home/pi/.node-red/node_modules/
mkdir node-red-contrib-radio-emi
cd node-red-contrib-radio-emi/
wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1cFD3ueWznk4zOMeiHWCzGthGOw08aQeB' -O radioEmission
sudo chmod 755 radioEmission

Pour tester :

sudo ./radioEmission 0 12325261 1 on
sudo ./radioEmission 0 12325261 1 off

Importer le flow suivant dans Node-red:

[{"id":"f28896f.bd25a68","type":"function","z":"a8893c87.db65f","name":"Filtre Emission","func":"var ws = msg.payload;\n\nif(ws==\"prise_1_on\"){ //Si appui sur le bouton 1 ON de la télécommande virtuelle\n var msg1 = { payload:\"sudo /home/pi/.node-red/node_modules/node-red-contrib-radio-emi/radioEmission 0 12325261 1 on\" }; //Création d'un objet comprenant la ligne de commande qui execute le programme en C++\n return [msg1]; //On retourne ce message vers la sortie de la node\n}\n\nif(ws==\"prise_1_off\"){\n var msg1 = { payload:\"sudo /home/pi/.node-red/node_modules/node-red-contrib-radio-emi/radioEmission 0 12325261 1 off\" };\n return [msg1]; \n}\n\nif(ws==\"prise_2_on\" || ws==\"prise_2_onemi\"){\n var msg1 = { payload:\"sudo /home/pi/.node-red/node_modules/node-red-contrib-radio-emi/radioEmission 0 12325261 2 on\" };\n return [msg1];\n}\n\nif(ws==\"prise_2_off\" || ws==\"prise_2_offemi\"){\n var msg1 = { payload:\"sudo /home/pi/.node-red/node_modules/node-red-contrib-radio-emi/radioEmission 0 12325261 2 off\" };\n return [msg1];\n}\n\nif(ws==\"prise_3_on\" || ws==\"prise_3_onemi\"){\n var msg1 = { payload:\"sudo /home/pi/.node-red/node_modules/node-red-contrib-radio-emi/radioEmission 0 12325261 3 on\" };\n return [msg1];\n}\n\nif(ws==\"prise_3_off\" || ws==\"prise_3_offemi\"){\n var msg1 = { payload:\"sudo /home/pi/.node-red/node_modules/node-red-contrib-radio-emi/radioEmission 0 12325261 3 off\" };\n return [msg1];\n}","outputs":1,"noerr":0,"x":320,"y":120,"wires":[["b1e419cd.fff3d8"]]},{"id":"b1e419cd.fff3d8","type":"exec","z":"a8893c87.db65f","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"radioEmission","x":580,"y":120,"wires":[[],[],[]]},{"id":"6bf9a685.527338","type":"ui_switch","z":"a8893c87.db65f","name":"Prise 1","label":"Prise 1","group":"aeb1704d.6d297","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"prise_1_on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"prise_1_off","offvalueType":"str","officon":"","offcolor":"","x":110,"y":60,"wires":[["f28896f.bd25a68"]]},{"id":"145e2a46.8168e6","type":"ui_switch","z":"a8893c87.db65f","name":"Prise 2","label":"Prise 2","group":"aeb1704d.6d297","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"prise_2_on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"prise_2_off","offvalueType":"str","officon":"","offcolor":"","x":110,"y":120,"wires":[["f28896f.bd25a68"]]},{"id":"2f8a95f5.d3948a","type":"ui_switch","z":"a8893c87.db65f","name":"Prise 3","label":"Prise 3","group":"aeb1704d.6d297","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"prise_3_on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"prise_3_off","offvalueType":"str","officon":"","offcolor":"","x":110,"y":180,"wires":[["f28896f.bd25a68"]]},{"id":"aeb1704d.6d297","type":"ui_group","z":"","name":"Commandes","tab":"777713cf.aa843c","order":3,"disp":true,"width":"6","collapse":false},{"id":"777713cf.aa843c","type":"ui_tab","z":"","name":"Ecran Principal","icon":"home","order":1}]

 

 

Le jeu de 421 électronique

Un aperçu de ce que pourrait donner ce jeu de 421, avec un affichage lumineux dans des dalles d’Altuglas gravées.

L’affichage de la valeur d’un dé se fait avec seulement 4 « allumages » de led :

  1. une led centrale
  2. deux leds au milieu de chaque cotés
  3. une led en bas à gauche et une led en haut à droite, groupées. (+ le 1 bien sur)
  4. une led en haut à gauche et une led en bas à droite, groupées. (+ le 3 )
  5. = le 4 + le 3 et le 1
  6. = le 2 + le 3 et le 4

Un câblage qui utilise toutes les entrées-sorties de la carte ! :

  • 4 X 3 sorties leds pour les 3 dés
  • 4 entrées pour les boutons
  • 2 entrées pour l’affichage 7 segments

Un aperçu du programme arduino (à améliorer certes !)

#include "SevenSegmentTM1637.h"

const int D1_1 = 2; // the number of the pushbutton pin
const int D1_2 = 3; // the number of the pushbutton pin
const int D1_3 = 4; // the number of the pushbutton pin
const int D1_4 = 5; // the number of the pushbutton pin
const int D2_1 = 6; // the number of the pushbutton pin
const int D2_2 = 7; // the number of the pushbutton pin
const int D2_3 = 8; // the number of the pushbutton pin
const int D2_4 = 9; // the number of the pushbutton pin
const int D3_1 = 10; // the number of the pushbutton pin
const int D3_2 = 11; // the number of the pushbutton pin
const int D3_3 = 12; // the number of the pushbutton pin
const int D3_4 = 13; // the number of the pushbutton pin

const int Bt_1 = 15; // the number of the pushbutton pin
const int Bt_2 = 16; // the number of the pushbutton pin
const int Bt_3 = 17; // the number of the pushbutton pin
const int Bt_G = 14; // the number of the pushbutton pin
const byte PIN_CLK = 18; // define CLK pin (any digital pin)
const byte PIN_DIO = 19; // define DIO pin (any digital pin)

int Temps = 2000;
bool Bt_GState = 0;
bool Bt_1State = 0;
bool Bt_2State = 0;
bool Bt_3State = 0;
bool D1 = 0;
bool D2 = 0;
bool D3 = 0;
bool Jeu = 0; // jeu = 0 : charge ; jeu = 1 : decharge
bool Joueur = 0 ; //joueur1 = 0 : joueur2 = 1
bool Debut = 0 ; // debut = 0 joueur1 debute sinon joueur2
int Val = 0;
int Val1 = 0;
int Val2 = 0;
int Score = 0;
int Score1 = 0 ;
int Score2 = 0 ;
int Jetons1 = 0 ;
int Jetons2 = 0 ;
int Lance = 0; // si jeu = 1 lance = 3
int Pot = 21;
int Temp ;
String Seg;
 String ScoreT;
int Tirage[3];

SevenSegmentTM1637 display(PIN_CLK, PIN_DIO);

void setup() {
 Serial.begin(9600); // initializes the Serial connection @ 9600 baud
 display.begin(); // initializes the display
 display.setBacklight(100); // set the brightness to 100 %
 display.print("INIT"); // display INIT on the display


 pinMode(14, INPUT_PULLUP);
 pinMode(15, INPUT_PULLUP);
 pinMode(16, INPUT_PULLUP);
 pinMode(17, INPUT_PULLUP);
 for (int thisPin = 2; thisPin < 14; thisPin++) {
 pinMode(thisPin, OUTPUT);
 }
 randomSeed(analogRead(7));
 delay(Temps); // wait 1000 ms
 Efface();
 Affiche(1, 4);
 Affiche(2, 2);
 Affiche(3, 1);
 delay(Temps);
 Efface();
}

void loop() {

while (Pot < 22 && Pot > 0) { // phase de charge
 Jeu = false;
 
 if(!Joueur){
 Efface();
// Serial.print("Joueur : ");
// Serial.println(Joueur + 1);
 while(!Bt_GState && !Joueur) {
 AfficheJoueur(); 
 if (digitalRead(Bt_G) == LOW){ Bt_GState = 1;
 //Serial.println("Prêt au Lancement des dés");
 }
 LanceCharge();
 }
 }
 
 if(Joueur){
 Efface();
// Serial.print("Joueur : ");
// Serial.println(Joueur + 1);
 while(!Bt_GState && Joueur) {
 AfficheJoueur();
 if (digitalRead(Bt_G) == LOW){ Bt_GState = 1;
 Serial.println("Prêt au Lancement des dés J2");
 }
 LanceCharge();
 }
 }
 }
 if (Pot == 0 && Jeu == false) { // phase de decharge
 if (Jetons1 > Jetons2) {
 int tmp = Jetons1;
 Jetons1 = Jetons2;
 Jetons2 = tmp;
 }
 Jeu = true;
 display.clear();
 display.setColonOn(0);
 display.print("DECHARGE"); 
 Joueur = 0;
 AfficheJoueur();
// Serial.print("Passage en phase decharge : ");
// Serial.println(Jeu);
 Efface();
 }

while (Jetons1 > 0 && Jetons2 > 0 && Jeu == true) {
 
 if(!Joueur){
 
 while(!Bt_GState && !Joueur) {
 AfficheJoueur(); 
 Efface();
 if (digitalRead(Bt_G) == LOW){ Bt_GState = 1;Serial.println("Prêt au Lancement des dés");}
 
 if (Lance != 0) {
 if (digitalRead(Bt_1) == LOW){ Bt_1State = !Bt_1State;Serial.println("Verouillage D1");}
 if (digitalRead(Bt_2) == LOW){ Bt_2State = !Bt_2State;Serial.println("Verouillage D2");}
 if (digitalRead(Bt_3) == LOW){ Bt_3State = !Bt_3State;Serial.println("Verouillage D3");}
 
 if (Bt_1State){ D1=1; 
 Affiche(1, Tirage[0]);}
 if (Bt_2State){ D2=1; 
 Affiche(2, Tirage[1]);}
 if (Bt_3State){ D3=1; 
 Affiche(3, Tirage[2]);}
 }
 
 LanceDecharge();
 
}
 }
 if(Joueur){
 
 while(!Bt_GState && Joueur) {
 AfficheJoueur(); 
 Efface();
 if (digitalRead(Bt_G) == LOW){ Bt_GState = 1;Serial.println("Prêt au Lancement des dés");}

if (Lance != 0) {
 if (digitalRead(Bt_1) == LOW){ Bt_1State = !Bt_1State; }
 if (digitalRead(Bt_2) == LOW){ Bt_2State = !Bt_2State; }
 if (digitalRead(Bt_3) == LOW){ Bt_3State = !Bt_3State; }
 
 if (Bt_1State){ D1=1; 
 Affiche(1, Tirage[0]);}
 if (Bt_2State){ D2=1; 
 Affiche(2, Tirage[1]);}
 if (Bt_3State){ D3=1; 
 Affiche(3, Tirage[2]);}
 }


LanceDecharge();
}
}
 }
 if(Pot==0 && Jetons1==0){display.clear();
 display.setColonOn(0);
 display.print("JOUEUR 1 GAGNE"); 
 if (digitalRead(Bt_G) == LOW){
 Jeu = 0; Jetons1 = Jetons2 = 0 ; Pot = 21; display.clear(); display.print("Reset");}
 }
 if(Pot==0 && Jetons2==0){display.clear();
 display.setColonOn(0);
 display.print("JOUEUR 2 GAGNE"); 
 if (digitalRead(Bt_G) == LOW){
 Jeu = 0; Jetons1 = Jetons2 = 0 ; Pot = 21; display.clear(); display.print("Reset");}}
}
void Efface() {
 //if(!D1) {
 digitalWrite (D1_1, LOW);
 digitalWrite (D1_2, LOW);
 digitalWrite (D1_3, LOW);
 digitalWrite (D1_4, LOW);
 // }
 // if(!D2) {
 digitalWrite (D2_1, LOW);
 digitalWrite (D2_2, LOW);
 digitalWrite (D2_3, LOW);
 digitalWrite (D2_4, LOW);
 //}
 //if(!D3) {
 digitalWrite (D3_1, LOW);
 digitalWrite (D3_2, LOW);
 digitalWrite (D3_3, LOW);
 digitalWrite (D3_4, LOW);
 //}
}
void LanceCharge() {
 
 if (Bt_GState == 1 && Jeu == false) {
 Serial.println("Lancement des dés");
 //Efface();
 Tirage[0] = random(1, 7); Tirage[1] = random(1, 7); Tirage[2] = random(1, 7);

Tri();
 
// Serial.print("Tirage : ");
// Serial.print(Tirage[0]);
// Serial.print(Tirage[1]);
// Serial.println(Tirage[2]);

Affiche(1, Tirage[0]);
 Affiche(2, Tirage[1]);
 Affiche(3, Tirage[2]);
 delay (Temps);


CalculScore();
// Serial.println("Calcul score");
 if(Joueur){ CalculJetons();
 AfficheJetons();
 }
 Joueur = !Joueur;
// Serial.print("Passage au joueur : ");
// Serial.println(Joueur + 1);
 Bt_GState = 0; //Serial.println("Remise à zéro du lancement");
 }
}
void LanceDecharge() {
 
 if (Bt_GState == 1 && Jeu == true) {
 Lance += 1;
// Serial.print("N° lancement: "); Serial.println(Lance);
// Serial.print("D1-D2-D3 avant tirage : ");
// Serial.print(D1); Serial.print(D2); Serial.println(D3);
 
 if (Lance < 4){
 
 if (!D1) {Tirage[0] = random(1, 7);}
 if (!D2) {Tirage[1] = random(1, 7);}
 if (!D3) {Tirage[2] = random(1, 7);}

Tri();
 
// Serial.print("Tirage Décharge: ");
// Serial.print(Tirage[0]);
// Serial.print(Tirage[1]);
// Serial.println(Tirage[2]);

Efface();

Affiche(1, Tirage[0]);
 Affiche(2, Tirage[1]);
 Affiche(3, Tirage[2]);

Bt_1State = Bt_2State = Bt_3State = D1 = D2 = D3 = 0;
 
delay (Temps);
 
 
 
 if(Lance==3){
 CalculScore(); Lance = 0;
// Serial.println("Calcul score Décharge");
 if(Joueur){
 CalculJetons();
// Serial.println("Calcul jetons Décharge");
 AfficheJetons();
// Serial.println("Affiche Jetons Decharge");}
 Joueur = !Joueur;
// Serial.print("Passage au joueur : ");
// Serial.println(Joueur + 1);
 }
 }
 
 Bt_GState = 0; //Serial.println("Remise à zéro du lancement"); 
 }
}

void Affiche(int nd, int d) {
 if (d == 1) {
 if (nd == 1) {
 digitalWrite (D1_1, HIGH);
 }
 if (nd == 2) {
 digitalWrite (D2_1, HIGH);
 }
 if (nd == 3) {
 digitalWrite (D3_1, HIGH);
 }
 }
 if (d == 2) {
 if (nd == 1) {
 digitalWrite (D1_2, HIGH);
 }
 if (nd == 2) {
 digitalWrite (D2_2, HIGH);
 }
 if (nd == 3) {
 digitalWrite (D3_2, HIGH);
 }
 }
 if (d == 3) {
 if (nd == 1) {
 digitalWrite (D1_1, HIGH);
 digitalWrite (D1_3, HIGH);
 }
 if (nd == 2) {
 digitalWrite (D2_1, HIGH);
 digitalWrite (D2_3, HIGH);
 }
 if (nd == 3) {
 digitalWrite (D3_1, HIGH);
 digitalWrite (D3_3, HIGH);
 }
 }
 if (d == 4) {
 if (nd == 1) {
 digitalWrite (D1_4, HIGH);
 digitalWrite (D1_3, HIGH);
 }
 if (nd == 2) {
 digitalWrite (D2_4, HIGH);
 digitalWrite (D2_3, HIGH);
 }
 if (nd == 3) {
 digitalWrite (D3_4, HIGH);
 digitalWrite (D3_3, HIGH);
 }
 }
 if (d == 5) {
 if (nd == 1) {
 digitalWrite (D1_1, HIGH);
 digitalWrite (D1_3, HIGH);
 digitalWrite (D1_4, HIGH);
 }
 if (nd == 2) {
 digitalWrite (D2_1, HIGH);
 digitalWrite (D2_3, HIGH);
 digitalWrite (D2_4, HIGH);
 }
 if (nd == 3) {
 digitalWrite (D3_1, HIGH);
 digitalWrite (D3_3, HIGH);
 digitalWrite (D3_4, HIGH);
 }
 }
 if (d == 6) {
 if (nd == 1) {
 digitalWrite (D1_2, HIGH);
 digitalWrite (D1_3, HIGH);
 digitalWrite (D1_4, HIGH);
 }
 if (nd == 2) {
 digitalWrite (D2_2, HIGH);
 digitalWrite (D2_3, HIGH);
 digitalWrite (D2_4, HIGH);
 }
 if (nd == 3) {
 digitalWrite (D3_2, HIGH);
 digitalWrite (D3_3, HIGH);
 digitalWrite (D3_4, HIGH);
 }
 }
}
void Tri() {
 while (Tirage[0] < Tirage[1] || Tirage[0] < Tirage[2] || Tirage[1] < Tirage[2]) {
 if (Tirage[0] < Tirage[1]) {
 Temp = Tirage[0];
 Tirage[0] = Tirage[1];
 Tirage[1] = Temp;
 }
 if (Tirage[1] < Tirage[2]) {
 Temp = Tirage[1];
 Tirage[1] = Tirage[2];
 Tirage[2] = Temp;
 }
 }
}

void CalculScore() {
 // tri des des
 Tri();
 // combinaisons
 // 421
 if (Tirage[0] == 4 && Tirage[1] == 2 && Tirage[2] == 1 ) {
 Val = 100;
 (!Joueur) ? Val1 = Val : Val2 = Val;
 }
 
 // 111
 if (Tirage[0] == 1 && Tirage[1] == 1 && Tirage[2] == 1 ) {Val = 70;
(!Joueur) ? Val1 = Val : Val2 = Val;}
 
 // 666 - 611
 if ( Tirage[0] == Tirage[1] && Tirage[1] == Tirage[2] && Tirage[0] == 6 ) {Val = 66;
 (!Joueur) ? Val1 = Val : Val2 = Val;} 
 if ( Tirage[0] == 6 && Tirage[1] == 1 && Tirage[2] == 1 ) {Val = 65;
 (!Joueur) ? Val1 = Val : Val2 = Val;}
 
// 555 - 511
if ( Tirage[0] == Tirage[1] && Tirage[1] == Tirage[2] && Tirage[0] == 5 ) { Val = 55; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}
if ( Tirage[0] == 5 && Tirage[1] == 1 && Tirage[2] == 1 ) { Val = 54; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}

// 444 - 411
if ( Tirage[0] == Tirage[1] && Tirage[1] == Tirage[2] && Tirage[0] == 4 ) { Val = 44; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}
if ( Tirage[0] == 4 && Tirage[1] == 1 && Tirage[2] == 1 ) { Val = 43; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}
 
// 333 - 311
if ( Tirage[0] == Tirage[1] && Tirage[1] == Tirage[2] && Tirage[0] == 3 ) { Val = 33; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}
if ( Tirage[0] == 3 && Tirage[1] == 1 && Tirage[2] == 1 ) { Val = 32; 
 (!Joueur) ? Val1 = Val : Val2 = Val;
 }
// 222 - 211
if ( Tirage[0] == Tirage[1] && Tirage[1] == Tirage[2] && Tirage[0] == 2 ) { Val = 22; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}
if ( Tirage[0] == 2 && Tirage[1] == 1 && Tirage[2] == 1 ) { Val = 21; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}
 
// Suites
if ( Tirage[0] == 6 && Tirage[1] == 5 && Tirage[2] == 4 ) { Val = 20; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}
 if ( Tirage[0] == 5 && Tirage[1] == 4 && Tirage[2] == 3 ) { Val = 19; 
(!Joueur) ? Val1 = Val : Val2 = Val;}
 if ( Tirage[0] == 4 && Tirage[1] == 3 && Tirage[2] == 2 ) { Val = 18; 
(!Joueur) ? Val1 = Val : Val2 = Val;}
 if ( Tirage[0] == 3 && Tirage[1] == 2 && Tirage[2] == 1 ) { Val = 17; 
(!Joueur) ? Val1 = Val : Val2 = Val;}

//221 Nenette
if ( Tirage[0] == 2 && Tirage[1] == 2 && Tirage[2] == 1 ) { Val = 16; 
 (!Joueur) ? Val1 = Val : Val2 = Val;}

// Hors combinaisons
if ( Val1 == 0 && Val2 == 0){ 
Val =Tirage[0] * 100 + Tirage[1] * 10 + Tirage[2];
Val1 = Val; 
 //Serial.print("Hors combinaison J1 : ");
 //Serial.println(Val1);
} 
if (Val1>100 && Val2==0 && Joueur) { Val = 0;
 Val =Tirage[0] * 100 + Tirage[1] * 10 + Tirage[2];
Val2 = Val; 
 //Serial.print("Hors combinaison J2 : ");
 //Serial.println(Val2);
}

if (Joueur) {
 if ( Val1 - Val2 == 0 ) { Score1 = 0; Score2 = 0;}
 if ((Val1 <101 && Val1 > Val2 )||(Val1 <101 && Val2 > 100 )) {Score2 = 0;
 switch(Val1){
 case(100): Score1 = 10;break;
 case(70): Score1 = 7;break;
 case(66): Score1 = 6;break;
 case(65): Score1 = 6;break;
 case(55): Score1 = 5;break;
 case(54): Score1 = 5;break;
 case(44): Score1 = 4;break;
 case(43): Score1 = 4;break;
 case(33): Score1 = 3;break;
 case(32): Score1 = 3;break;
 case(22): Score1 = 2;break;
 case(21): Score1 = 2;break;
 case(20): Score1 = 2;break;
 case(19): Score1 = 2;break;
 case(18): Score1 = 2;break;
 case(17): Score1 = 2;break;
 case(16): Score1 = 4;break;
 default: Score1 = 1;break; 
 }
 }
 if ((Val2<101 && Val1 < Val2 )||(Val2 <101 && Val1 > 100 )) {Score1 = 0;
 switch(Val2){
 case(100): Score2 = 10;break;
 case(70): Score2 = 7;break;
 case(66): Score2 = 6;break;
 case(65): Score2 = 6;break;
 case(55): Score2 = 5;break;
 case(54): Score2 = 5;break;
 case(44): Score2 = 4;break;
 case(43): Score2 = 4;break;
 case(33): Score2 = 3;break;
 case(32): Score2 = 3;break;
 case(22): Score2 = 2;break;
 case(21): Score2 = 2;break;
 case(20): Score2 = 2;break;
 case(19): Score2 = 2;break;
 case(18): Score2 = 2;break;
 case(17): Score2 = 2;break;
 case(16): Score2 = 4;break;
 default: Score2 = 1;break; 
 }
 }
 if(Val1>100 && Val2>100) {
 if (Val1==Val2) { Score1=Score2=0 ; //Serial.println("Egalité Hors combinaison ");
 }
 if(Val1>Val2){ Score1=1;}
 if(Val2>Val1){ Score2=1;}
 }
 
 //Serial.print("Valeur Val1 : ");
// Serial.println(Val1);
// Serial.print("Valeur Val2 : ");
// Serial.println(Val2);
 Val1 = Val2 = 0;
// Serial.print("Calcul du score : ");
// Serial.println(Score1 + Score2);
}

}
 
void CalculJetons() {
 if (!Jeu) {
 if (Score1 > Pot) {
 Score1 = Pot;
 }
 if (Score2 > Pot) {
 Score2 = Pot;
 }
 if (Score1 > Score2) {
 Jetons2 = Jetons2 + Score1;
 }
 if (Score2 > Score1) {
 Jetons1 = Jetons1 + Score2;
 }
 Pot = Pot - Score1 - Score2;
 Score1 = Score2 = 0;
 
// Serial.print("Calcul du pot : ");
// Serial.println(Pot);
 }
 if(Jeu) {
 if (Score1 > Score2) {
 if (Score1 > Jetons1) {
 Score1 = Jetons1;
 }
 Jetons2 = Jetons2 + Score1;
 Jetons1 = Jetons1 - Score1;
 }
 if (Score2 > Score1) {
 if (Score2 > Jetons2) {
 Score2 = Jetons2;
 }
 Jetons1 = Jetons1 + Score2;
 Jetons2 = Jetons2 - Score2;
 }
 Score1 = Score2 = 0;
 }
 
}
void AfficheJetons(){
String str1;
 str1="J2";
String str2 = String(Jetons2);
if(Jetons2>=0 && Jetons2<=9){str2 = '0'+ str2;}
String str0 = str1 + str2;
display.clear();
 display.setColonOn(1);
 display.print(str0); // display LOOP on the display
delay(Temps); 
String str3;
 str3="J1";
String str4 = String(Jetons1);
if(Jetons1>=0 && Jetons1<=9){str4 = '0'+ str4;}
String str = str3 + str4;
display.clear();
 display.setColonOn(1);
 display.print(str); // display LOOP on the display 
delay(Temps);

// Serial.print("Jetons joueur 1 : ");
// Serial.println(Jetons1);
// Serial.print("Jetons joueur 2 : ");
// Serial.println(Jetons2);
}
void AfficheJoueur(){
 String str1;
(Joueur) ? str1="J2" : str1= "J1";
display.clear();
 display.setColonOn(1);
 display.print(str1); // display LOOP on the display
display.blink(); 
}

Voilà