add of setBtn function

This commit is contained in:
UNIV-LYON1\p2405212 2025-06-17 10:17:15 +02:00
parent de0afba0bf
commit 2062f238ca
3 changed files with 50 additions and 25 deletions

View File

@ -18,13 +18,13 @@ uint16_t currtouched = 0;
void setup() {
Serial.begin(115200);
/*
if (!cap.begin(0x5B)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
*/
setupMenu();
}
@ -33,7 +33,6 @@ void loop() {
readButton();
if (!isPlay) {
menu();
Serial.println("ok");
} else {
if (!local) {
if(!isWebSet){
@ -43,8 +42,12 @@ void loop() {
loopWeb();
}
} else {
// Passe cap, lasttouched, currtouched par référence !
localMode(cap, lasttouched, currtouched);
if(!isBtnSet){
setBtn(cap, lasttouched, currtouched);
}else{
// Passe cap, lasttouched, currtouched par référence !
localMode(cap, lasttouched, currtouched);
}
}
}
}

View File

@ -52,9 +52,33 @@ bool allInit();
void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
bool isBtnSet = false;
#endif // LOCALMODE_H
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) {
case 0: return { 0, 0 };
@ -107,31 +131,28 @@ void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouche
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;
if(victoire(grille, 1)) {
Serial.println("Joueur 1 a gagne");
}
} else {
grille[c.y][c.x] = 2;
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;
if(victoire(grille, 1)) {
Serial.println("Joueur 1 a gagne");
}
} else {
grille[c.y][c.x] = 2;
if(victoire(grille, 2)) {
Serial.println("Joueur 2 a gagne");
}
joueur1 = !joueur1;
}
joueur1 = !joueur1;
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
Serial.print(grille[i][j]);
}
Serial.println();
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
Serial.print(grille[i][j]);
}
Serial.println();
}
}
}

1
menu.h
View File

@ -17,6 +17,7 @@ bool isDifficulty = false;
bool isPlay = false;
bool isWebSet = false;
#define BUTTON_A 15
#define BUTTON_B 32
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);