add of setBtn function
This commit is contained in:
parent
de0afba0bf
commit
2062f238ca
@ -18,13 +18,13 @@ uint16_t currtouched = 0;
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
/*
|
|
||||||
if (!cap.begin(0x5B)) {
|
if (!cap.begin(0x5B)) {
|
||||||
Serial.println("MPR121 not found, check wiring?");
|
Serial.println("MPR121 not found, check wiring?");
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
Serial.println("MPR121 found!");
|
Serial.println("MPR121 found!");
|
||||||
*/
|
|
||||||
|
|
||||||
setupMenu();
|
setupMenu();
|
||||||
}
|
}
|
||||||
@ -33,7 +33,6 @@ void loop() {
|
|||||||
readButton();
|
readButton();
|
||||||
if (!isPlay) {
|
if (!isPlay) {
|
||||||
menu();
|
menu();
|
||||||
Serial.println("ok");
|
|
||||||
} else {
|
} else {
|
||||||
if (!local) {
|
if (!local) {
|
||||||
if(!isWebSet){
|
if(!isWebSet){
|
||||||
@ -42,9 +41,13 @@ void loop() {
|
|||||||
}else{
|
}else{
|
||||||
loopWeb();
|
loopWeb();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if(!isBtnSet){
|
||||||
|
setBtn(cap, lasttouched, currtouched);
|
||||||
}else{
|
}else{
|
||||||
// Passe cap, lasttouched, currtouched par référence !
|
// Passe cap, lasttouched, currtouched par référence !
|
||||||
localMode(cap, lasttouched, currtouched);
|
localMode(cap, lasttouched, currtouched);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
27
localMode.h
27
localMode.h
@ -52,9 +52,33 @@ bool allInit();
|
|||||||
|
|
||||||
void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
||||||
|
|
||||||
|
bool isBtnSet = false;
|
||||||
|
|
||||||
#endif // LOCALMODE_H
|
#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) {
|
Coord getCo(int key) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case 0: return { 0, 0 };
|
case 0: return { 0, 0 };
|
||||||
@ -107,9 +131,7 @@ void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouche
|
|||||||
|
|
||||||
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
||||||
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
||||||
btns[i] = true;
|
|
||||||
|
|
||||||
if(allInit()) {
|
|
||||||
Coord c = getCo(i);
|
Coord c = getCo(i);
|
||||||
if(grille[c.y][c.x] == 0) {
|
if(grille[c.y][c.x] == 0) {
|
||||||
if(joueur1) {
|
if(joueur1) {
|
||||||
@ -134,6 +156,5 @@ void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouche
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
lasttouched = currtouched;
|
lasttouched = currtouched;
|
||||||
}
|
}
|
||||||
1
menu.h
1
menu.h
@ -17,6 +17,7 @@ bool isDifficulty = false;
|
|||||||
bool isPlay = false;
|
bool isPlay = false;
|
||||||
bool isWebSet = false;
|
bool isWebSet = false;
|
||||||
|
|
||||||
|
|
||||||
#define BUTTON_A 15
|
#define BUTTON_A 15
|
||||||
#define BUTTON_B 32
|
#define BUTTON_B 32
|
||||||
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
|
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user