J'ai modifié comme suit :
puisCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 RTC_DATA_ATTR uint8_t etat[] = {0,0,0,0,0,0,0,0,0}; .... int buttonX = 20; int buttonY = 20; for (int i = 0; i < 9; ++i) { buttons[i].x = buttonX; buttons[i].y = buttonY; //buttons[i].state = false; buttons[i].state = etat[i]; // <================================= // Affichage des boutons drawButton(buttonX, buttonY, buttons[i].state); buttonX += BUTTON_WIDTH + BUTTON_MARGIN; if (buttonX + BUTTON_WIDTH > tft.width()) { buttonX = 20; buttonY += BUTTON_HEIGHT + BUTTON_MARGIN; } }
et çà fonctionne , j'ai bien une mise en mémoire des états de chaque boutonsCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 void loop() { currentTime=millis(); // Vérifie si l'écran tactile a été touché et imprime les informations X, Y et la pression (Z) sur l'écran TFT et le moniteur série. if (touchscreen.tirqTouched() && touchscreen.touched()) { previousTime=currentTime; // Get Touchscreen points TS_Point p = touchscreen.getPoint(); // Calibrate Touchscreen points with map function to the correct width and height touchX = map(p.x, 200, 3700, 1, SCREEN_WIDTH); touchY = map(p.y, 240, 3800, 1, SCREEN_HEIGHT); touchZ = p.z; //printTouchToSerial(touchX, touchY, touchZ); for (int i = 0; i < 9; ++i) { if (touchX >= buttons[i].x && touchX <= buttons[i].x + BUTTON_WIDTH && touchY >= buttons[i].y && touchY <= buttons[i].y + BUTTON_HEIGHT) { // Si un bouton est touché, inverse son état et met à jour l'affichage buttons[i].state = !buttons[i].state; drawButton(buttons[i].x, buttons[i].y, buttons[i].state); if (buttons[i].state == 1) { Serial.print("Btn "); Serial.print(i + 1); Serial.println(" enfoncé"); snprintf(myData.a, sizeof myData.a, "PC%02d=> ON", i + 1); myData.b = true; esp_err_t result = esp_now_send(clients[i].adresse, (uint8_t *)&myData, sizeof(myData)); if (result == ESP_OK) { Serial.print("PC"); Serial.print(i + 1); Serial.println(" Envoyé avec succès"); etat[i] = 1; <================================================ } else { Serial.print("Erreur d'envoi des données PC"); Serial.print(i + 1); } } if (buttons[i].state == 0) { Serial.print("Btn "); Serial.print(i + 1); Serial.println(" relaché"); snprintf(myData.a, sizeof myData.a, "PC%02d=> OFF", i + 1); myData.b = false; esp_err_t result = esp_now_send(clients[i].adresse, (uint8_t *)&myData, sizeof(myData)); if (result == ESP_OK) { Serial.print("PC"); Serial.print(i + 1); Serial.println(" Envoyé avec succès"); etat[i] = 0; // <================================================= } else { Serial.print("Erreur d'envoi des données PC"); Serial.print(i + 1); } } } //break; delay(200); } } if((currentTime-previousTime)>10000){ //Go to sleep now Serial.println("Je vais m'endormir maintenant"); delay(1000); esp_deep_sleep_start(); } }