Bonjour,
Bon à priori c'est bien le programme qui pose problème.
Je joins le code pour une meilleure compréhension. J'ai essayé d'écrire ce programme (étant novice) pour commander principalement la nettoyage d'un tambour. Avec un écran tactile, le but est de soit avec un programme qui exécute des tâches avec le mode filtration et de couper l'alimentation en mode baignade. J'ai du faire une erreur dans la partie filtration, puisque le programme fonctionne très bien pendant quelques minutes puis plante subitement.
J'essaye de chercher depuis un moment mais je bloque.
Désolé d'avance pour l'écriture du programme qui n'est surement pas très jolie...
merci d'avance pour votre aide
/***********************************************************************************
*This program is a demo of how to display picture and
*how to use rotate function to display string.
*This demo was made for LCD modules with 8bit or 16bit data port.
*This program requires the the LCDKIWI library.
* File : display_graphics.ino
* Hardware Environment: Arduino UNO&Mega2560
* Build Environment : Arduino
*Set the pins to the correct ones for your development shield or breakout board.
*This demo use the BREAKOUT BOARD only and use these 8bit data lines to the LCD,
*pin usage as follow:
* LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK
* Arduino Uno A3 A2 A1 A0 A4 10 11 12 13
*Arduino Mega2560 A3 A2 A1 A0 A4 10 11 12 13
* LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7
* Arduino Uno 8 9 2 3 4 5 6 7
*Arduino Mega2560 8 9 2 3 4 5 6 7
*Remember to set the pins to suit your display module!
*
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, QD electronic SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
**********************************************************************************/
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_KBV.h> //Hardware-specific library
#include <TouchScreen.h> //touch library
#include <Wire.h>
#define TOUCH_ORIENTATION 0
#define TITLE "TouchScreen.h Calibration"
//if the IC model is known or the modules is unreadable,you can use this constructed function
LCDWIKI_KBV mylcd(ILI9486,A3,A2,A1,A0,A4); //model,cs,cd,wr,rd,reset
//if the IC model is not known and the modules is readable,you can use this constructed function
//LCDWIKI_KBV mylcd(320,480,A3,A2,A1,A0,A4);//width,height,cs,cd,wr,rd,reset
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
// sonde temperature
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 53
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// fin sonde
TouchScreen mytouch(XP, YP, XM, YM, 300);
TSPoint tp;
void Read_Resistive(void)
{
tp = mytouch.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);
}
bool is_pressed(void)
{
bool state;
Read_Resistive();
state = (tp.z > 20 && tp.z < 1000);
return state;
}//Touchscreen_due branch uses Point
//display some string
const int FLOTH = 31; //flotteur haut fil rouge
const int FLOTB = 33; //flotteur bas fil noir
int Airlift = 35;
int O2 = 37;
int UV = 39;
int rincage = 43;
int tambour = 45;
int cascade = 47;
int egout = 49;
int arduino = 51;
uint32_t tx;
uint32_t ty;
int Etat_tambour = LOW; //ledState utilisé pour régler l'état de la LED
unsigned long previousMillis = 0; //stockera la valeur de la dernière fois que la LED a été mise à jour
unsigned long interval;
unsigned long interval1 = 600000 ; //Temps entre chaque rotation
unsigned int interval2 = 4000; //Durée de rotation
void setup()
{
Serial.begin(9600);
sensors.begin();//sonde temp
// проверка наличия модуля на линии i2c
tp = mytouch.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);
//rinçage tambour
pinMode(FLOTH,INPUT);
pinMode(FLOTB,INPUT);
pinMode(Airlift,OUTPUT);
pinMode(O2,OUTPUT);
pinMode(UV,OUTPUT);
pinMode(rincage,OUTPUT);
pinMode(tambour,OUTPUT);
pinMode(arduino, OUTPUT);
//fin de rinçage tambour
mylcd.Init_LCD();
Serial.println(mylcd.Read_ID(), HEX);
delay(500);
for(uint8_t rotation=1; rotation<2; rotation++)
{
mylcd.Set_Rotation(rotation);
}
mylcd.Set_Text_Mode(0);
mylcd.Fill_Screen(BLACK);
mylcd.Fill_Rect(0, 0, 500, 30, WHITE);
mylcd.Draw_Pixe(400, 280, YELLOW);
mylcd.Set_Text_Back_colour(BLACK);
mylcd.Set_Text_colour(BLACK);
mylcd.Set_Text_Size(3);
mylcd.Print_String("GESTION BASSIN", 120, 5);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("Airlift :", 5, 40);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("OFF", 180, 40);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("O2 Filtre", 5, 80);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("UV", 5, 120);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("OFF", 180, 120);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("Rincage", 5, 160);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("OFF", 180, 160);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("Tambour", 5, 200);
mylcd.Print_String("ON", 120, 200);
mylcd.Print_String("OFF", 180, 200);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("Cascade", 260, 40);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("OFF", 410, 40);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("Egout", 260, 80);
mylcd.Print_String("ON", 360, 80);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("Temp :", 260, 200);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("_________________ :", 260, 120);
}
void loop() {
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
float tempC = sensors.getTempCByIndex(0);
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
mylcd.Set_Text_colour(CYAN);
mylcd.Set_Text_Size(2);
mylcd.Print_String("FOND :", 260, 200);
mylcd.Print_String(String(tempC), 360, 200);
mylcd.Print_String("`C", 420, 200);
Serial.println(tempC);
delay(1000); }
else
{
Serial.println("Error: Could not read temperature data");
}
{if (is_pressed()) { // met à jour le point tp
if (tp.x <= 300 && tp.y <= 200) {
mylcd.Set_Text_colour(CYAN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode BAIGNADE - ****ACTIVE****", 0, 250);
mylcd.Print_String(" ", 10, 290);
Serial.print("baignade appuyée");
baignade();
}
else if (tp.x > 400 && tp.y > 300) {
mylcd.Set_Text_colour(GREEN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode FILTRATION - ****ACTIF****", 0, 250);
mylcd.Print_String(" ", 0, 250);
Serial.print("Filtration appuyée");
filtration();
delay(1000);
}
else{
filtration();
}
delay(1000);
}
}}
void baignade() {
if (digitalRead(FLOTH) == 0 & digitalRead(FLOTB)== 0){
mylcd.Set_Text_colour(CYAN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode BAIGNADE - ****ACTIVE****", 0, 250);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 40);
mylcd.Print_String("OFF", 180, 120);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
mylcd.Print_String("OFF", 410, 40);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("ON", 360, 80);
digitalWrite(Airlift,LOW);
digitalWrite(O2,LOW);
digitalWrite(UV,LOW);
digitalWrite(rincage,LOW);
digitalWrite(tambour,LOW);
digitalWrite(cascade,LOW);
digitalWrite(egout,LOW);
digitalWrite(arduino,LOW);
}
if (digitalRead(FLOTH) == 1 & digitalRead(FLOTB)== 0){
mylcd.Set_Text_colour(CYAN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode BAIGNADE - ****ACTIVE****", 0, 250);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 40);
mylcd.Print_String("OFF", 180, 120);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
mylcd.Print_String("OFF", 410, 40);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("ON", 360, 80);
digitalWrite(Airlift,LOW);
digitalWrite(O2,LOW);
digitalWrite(UV,LOW);
digitalWrite(rincage,LOW);
digitalWrite(tambour,LOW);
digitalWrite(cascade,LOW);
digitalWrite(egout,LOW);
digitalWrite(arduino,LOW);
}
if (digitalRead(FLOTH) == 1 & digitalRead(FLOTB)== 1){
mylcd.Set_Text_colour(CYAN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode BAIGNADE - ****ACTIVE****", 0, 250);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 40);
mylcd.Print_String("OFF", 180, 120);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
mylcd.Print_String("OFF", 410, 40);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("ON", 360, 80);
digitalWrite(Airlift,LOW);
digitalWrite(O2,LOW);
digitalWrite(UV,LOW);
digitalWrite(rincage,LOW);
digitalWrite(tambour,LOW);
digitalWrite(cascade,LOW);
digitalWrite(egout,LOW);
digitalWrite(arduino,LOW);
}
if (is_pressed()) { // met à jour le point tp
if (tp.x > 400 && tp.y > 300) {
Serial.print("Filtration appuyée");
filtration();
}
else{
baignade();
}
}
{
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
float tempC = sensors.getTempCByIndex(0);
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("FOND :", 260, 200);
mylcd.Print_String(String(tempC), 360, 200);
mylcd.Print_String("`C", 420, 200);
Serial.println(tempC);
}
else
{
Serial.println("Error: Could not read temperature data");
}
}
}
void filtration(){
unsigned long currentMillis = millis(); // enregistre la lecture du temps écoulé dans currentMillis
{Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
float tempC = sensors.getTempCByIndex(0);
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
}
else
{
Serial.println("Error: Could not read temperature data");
}
if ((tempC)<10)
{
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("FOND :", 260, 200);
mylcd.Set_Text_colour(CYAN);
mylcd.Print_String(String(tempC), 360, 200);
mylcd.Print_String("`C", 420, 200);
}
if (10<(tempC)<28)
{
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("FOND :", 260, 200);
mylcd.Set_Text_colour(GREEN);
mylcd.Print_String(String(tempC), 360, 200);
//mylcd.Print_String(String((char)247), 420, 200);
mylcd.Print_String("`C", 420, 200);
}
if ((tempC)>28)
{
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(2);
mylcd.Print_String("FOND :", 260, 200);
mylcd.Set_Text_colour(RED);
mylcd.Print_String(String(tempC), 360, 200);
mylcd.Print_String("`C", 420, 200);
}}
if (digitalRead(FLOTH) == 0 & digitalRead(FLOTB)== 0){
Serial.print("NIVEAU HAUT");
mylcd.Set_Text_colour(RED);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode DEFAUT - ****NIVEAU HAUT****", 0, 250);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 40);
mylcd.Print_String("OFF", 180, 120);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
mylcd.Print_String("OFF", 410, 40);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("ON", 360, 80);
digitalWrite(Airlift,LOW);
digitalWrite(O2,LOW);
digitalWrite(UV,LOW);
digitalWrite(rincage,LOW);
digitalWrite(tambour,LOW);
digitalWrite(cascade,LOW);
digitalWrite(egout,LOW);
digitalWrite(arduino,LOW);
}
if (digitalRead(FLOTH) == 1 & digitalRead(FLOTB)== 0){
Serial.print("Lavage TAMBOUR");
mylcd.Set_Text_colour(GREEN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode LAVAGE - *****TAMBOUR*****", 0, 250);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("OFF", 180, 40);
mylcd.Print_String("OFF", 180, 80);
mylcd.Print_String("OFF", 180, 120);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
mylcd.Print_String("OFF", 410, 40);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(GREEN);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("ON", 360, 80);
digitalWrite(Airlift,LOW);
digitalWrite(O2,LOW);
digitalWrite(UV,LOW);
digitalWrite(tambour,HIGH);
digitalWrite(rincage,HIGH);
digitalWrite(cascade,HIGH);
digitalWrite(egout,HIGH);
digitalWrite(arduino,HIGH);
mylcd.Print_String(" Mode LAVAGE - *****EN COURS*****", 0, 250);
delay(12000);
mylcd.Print_String(" Mode LAVAGE - *****ATTENTE*****", 0, 250);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
digitalWrite(tambour,LOW);
digitalWrite(rincage,LOW);
delay(30000);
}
if (digitalRead(FLOTH) == 1 & digitalRead(FLOTB)== 1){
Serial.print("FiltrationOK");
mylcd.Set_Text_colour(GREEN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode FILTRATION - ****ACTIF****", 0, 250);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("OFF", 180, 40);
mylcd.Print_String("OFF", 180, 80);
mylcd.Print_String("OFF", 180, 120);
mylcd.Print_String("OFF", 410, 40);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(GREEN);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("ON", 360, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
digitalWrite(Airlift,HIGH);
digitalWrite(O2,HIGH);
digitalWrite(UV,HIGH);
digitalWrite(rincage,LOW);
digitalWrite(cascade,HIGH);
digitalWrite(egout,HIGH);
digitalWrite(arduino,HIGH); }
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if (Etat_tambour == LOW)
{
Etat_tambour = HIGH; //on l'allume la LED
Serial.print("Tambour en rotation");
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("OFF", 180, 200);
mylcd.Set_Text_colour(GREEN);
mylcd.Print_String("ON", 120, 200);
mylcd.Set_Text_colour(GREEN);
mylcd.Print_String(" Rotation Tambour", 0, 290);
//défini le nouvel intervalle de clignotement
interval = interval2;
delay(100);
} else
{
Etat_tambour= LOW;
Serial.print("Tambour arrete");
mylcd.Print_String(" ", 50, 290);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 200);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 200);//on l'éteint la LED
interval = interval1;
delay(100);
//défini le nouvel intervalle de clignotement
}
digitalWrite(tambour, Etat_tambour);
Serial.print("fin de code");
}
if (is_pressed()) { // met à jour le point tp
if (tp.x <= 300 && tp.y <= 200) {
Serial.print("baignade appuyée");
mylcd.Set_Text_colour(CYAN);
mylcd.Set_Text_Size(2);
mylcd.Print_String(" Mode BAIGNADE - *****ACTIVE*****", 0, 250);
mylcd.Print_String("OFF", 180, 80);
mylcd.Set_Text_colour(RED);
mylcd.Print_String("OFF", 180, 40);
mylcd.Print_String("OFF", 180, 120);
mylcd.Print_String("OFF", 180, 160);
mylcd.Print_String("OFF", 180, 200);
mylcd.Print_String("OFF", 410, 40);
mylcd.Print_String("OFF", 410, 80);
mylcd.Set_Text_colour(WHITE);
mylcd.Print_String("ON", 120, 40);
mylcd.Print_String("ON", 120, 80);
mylcd.Print_String("ON", 120, 120);
mylcd.Print_String("ON", 120, 160);
mylcd.Print_String("ON", 120, 200);
mylcd.Print_String("ON", 360, 40);
mylcd.Print_String("ON", 360, 80);
digitalWrite(Airlift,LOW);
digitalWrite(O2,LOW);
digitalWrite(UV,LOW);
digitalWrite(rincage,LOW);
digitalWrite(tambour,LOW);
digitalWrite(cascade,LOW);
digitalWrite(egout,LOW);
digitalWrite(arduino,LOW);
}
}
else if (tp.x > 400 && tp.y > 300) {
Serial.print("Filtration appuyée");
filtration();}
delay(1000);
}