From 638b01db24a6087f75de0acf53a9ea3b59c94158 Mon Sep 17 00:00:00 2001 From: Pyramond Date: Tue, 17 Jun 2025 10:46:24 +0200 Subject: [PATCH] Fix merge --- gra_21_morpion_lumineux_code.ino | 10 +--- localMode.cpp | 99 +++++++++++++++++++------------- localMode.h | 2 + 3 files changed, 62 insertions(+), 49 deletions(-) diff --git a/gra_21_morpion_lumineux_code.ino b/gra_21_morpion_lumineux_code.ino index 1bf4e79..f110845 100644 --- a/gra_21_morpion_lumineux_code.ino +++ b/gra_21_morpion_lumineux_code.ino @@ -19,20 +19,11 @@ void setup() { randomSeed(analogRead(0)); pinMode(A2, INPUT); - -<<<<<<< gra_21_morpion_lumineux_code.ino - -======= ->>>>>>> gra_21_morpion_lumineux_code.ino if (!cap.begin(0x5B)) { Serial.println("MPR121 not found, check wiring?"); while (1); } Serial.println("MPR121 found!"); -<<<<<<< gra_21_morpion_lumineux_code.ino - -======= ->>>>>>> gra_21_morpion_lumineux_code.ino setupMenu(); } @@ -61,4 +52,5 @@ void loop() { } } } + } } diff --git a/localMode.cpp b/localMode.cpp index f1917b9..986bb62 100644 --- a/localMode.cpp +++ b/localMode.cpp @@ -1,5 +1,9 @@ #include "localMode.h" #include +#include +#include + +extern Adafruit_SH1107 display; MechKey keys[] = { {0, A0, false, Adafruit_NeoPixel(1, A0, NEO_GRB + NEO_KHZ800)}, @@ -23,6 +27,29 @@ int grille[3][3] = { bool btns[9] = { false, false, false, false, false, false, false, false, false }; bool joueur1 = true; +bool isBtnSet = false; + +void setBtn(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched){ + display.clearDisplay(); + display.setCursor(0, 0); + display.print("Veuillez rester\nappuye sur chaqu'un\ndes boutons pendant\n3 secondes avant de\nles relacher pour\nles initialiser"); + display.display(); + if(allInit()){ + isBtnSet = true; + }else{ + currtouched = cap.touched(); + for (int i = 0; i < numKeys; i++) { + uint8_t t = keys[i].touchID; + keys[i].led.setPixelColor(0, 255); // Bleu + keys[i].led.show(); + if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) { + Serial.print("Touch "); Serial.print(t); Serial.println(" pressed"); + btns[i] = true; + } + } + lasttouched = currtouched; + } +} Coord getCo(int key) { switch(key) { @@ -97,26 +124,23 @@ void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtou if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) { Serial.print("Touch "); Serial.print(t); Serial.println(" pressed"); - btns[i] = true; - if(allInit()) { - Coord c = getCo(i); - if(grille[c.y][c.x] == 0) { - if(joueur1) { - grille[c.y][c.x] = 1; - afficheGrille(); - if(victoire(grille, 1)) { - Serial.println("Joueur 1 a gagne"); - } - } else { - grille[c.y][c.x] = 2; - afficheGrille(); - if(victoire(grille, 2)) { - Serial.println("Joueur 2 a gagne"); - } + Coord c = getCo(i); + if(grille[c.y][c.x] == 0) { + if(joueur1) { + grille[c.y][c.x] = 1; + afficheGrille(); + if(victoire(grille, 1)) { + Serial.println("Joueur 1 a gagne"); + } + } else { + grille[c.y][c.x] = 2; + afficheGrille(); + if(victoire(grille, 2)) { + Serial.println("Joueur 2 a gagne"); } - joueur1 = !joueur1; } + joueur1 = !joueur1; } } } @@ -129,35 +153,30 @@ void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currto for (int i = 0; i < numKeys; i++) { uint8_t t = keys[i].touchID; - keys[i].led.setPixelColor(0, 255); // Bleu - keys[i].led.show(); if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) { Serial.print("Touch "); Serial.print(t); Serial.println(" pressed"); - btns[i] = true; - if(allInit()) { - Coord c = getCo(i); - if(grille[c.y][c.x] == 0) { - grille[c.y][c.x] = 1; - afficheGrille(); - if(victoire(grille, 1)) { - Serial.println("Joueur 1 a gagne"); - } + Coord c = getCo(i); + if(grille[c.y][c.x] == 0) { + grille[c.y][c.x] = 1; + afficheGrille(); + if(victoire(grille, 1)) { + Serial.println("Joueur 1 a gagne"); + } - int x, y; - do { - x = random(0, 3); - y = random(0, 3); - } while(grille[y][x] != 0); + int x, y; + do { + x = random(0, 3); + y = random(0, 3); + } while(grille[y][x] != 0); - grille[y][x] = 2; - afficheGrille(); - if(victoire(grille, 2)) { - Serial.println("Joueur 2 a gagne"); - } - } - } + grille[y][x] = 2; + afficheGrille(); + if(victoire(grille, 2)) { + Serial.println("Joueur 2 a gagne"); + } + } } } lasttouched = currtouched; diff --git a/localMode.h b/localMode.h index 675f210..6c14c07 100644 --- a/localMode.h +++ b/localMode.h @@ -27,12 +27,14 @@ extern const int numKeys; extern int grille[3][3]; extern bool btns[9]; extern bool joueur1; +extern bool isBtnSet; Coord getCo(int key); bool victoire(int grille[3][3], int joueur); bool allInit(); void afficheGrille(); void reset(); +void setBtn(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched); void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched); void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);