Assemblage de 2 programmes

Bonjour, je suis en terminale STI2D j'aurai besoin d'un peu d'aide pour mon projet de fin d'année.
Mon projet consiste à réaliser un robot dirigeable à l'aide d'un écran tactile.
Pour ma part j'ai réaliser la partie déplacement du projet et un des mes camarades c'est occupé de créer des boutons sur l'écran tactile adafruit et maintenant que nous avons chacun un programme qui fonctionne nous devons les assembler afin de les mettre sur le même arduino et qu'ainsi lorsque que l'on appuis par exemple sur le bouton "avancer" de l'écran le robot avance.

Voici mon programme avec les 4 variables "avancer" "reculer" "droite" "gauche" :

// définition des broches utilisées sur carte de commande RS011MC
int direction_moteur_droite = 7;
int direction_moteur_gauche = 4;
int controle_moteur_droite = 6;
int controle_moteur_gauche = 5;

void moteur (int moteur_gauche, boolean sens_moteur_gauche, int moteur_droite, boolean sens_moteur_droite)
{
  // définition sens moteur LOW avance, HIGH recule
  digitalWrite(direction_moteur_gauche, sens_moteur_gauche);
  analogWrite(controle_moteur_gauche, moteur_gauche);
  digitalWrite(direction_moteur_droite, sens_moteur_droite);
  analogWrite(controle_moteur_droite, moteur_droite);
}

void setup()
{
  int i;
  for (i=4;i<=7;i++){
    pinMode(i, OUTPUT); //définit les port 4 à 7 en sortie
  }
  analogWrite(controle_moteur_gauche, 0); // arrêt moteur gauche
  analogWrite(controle_moteur_droite, 0); // arrêt moteur droite

}

void loop()
{
 
     moteur(250, HIGH, 250, HIGH); //Avancer

    //moteur(250, LOW, 250, LOW); //Reculer

    //moteur(250, HIGH, 0, HIGH); // Droite

    //moteur(0, HIGH, 250, HIGH); //Gauche
}

et voici celui qui des boutons :

//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.
//
//Thanks to Adafruit forums member Asteroid for the original sketch!
//
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>

// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

#define BOXSIZE 40

#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#define Btn 40

boolean RecordOn = false;


void setup(void)
{
  Serial.begin(9600);
  tft.begin();
  if (!ts.begin()) { 
    Serial.println("Unable to start touchscreen.");
  } 
  else { 
    Serial.println("Touchscreen started."); 
  }

  tft.fillScreen(ILI9341_BLACK);
  // origin = left,top landscape (USB left upper) 
  tft.fillRect(0 ,50 ,BOXSIZE ,BOXSIZE, ILI9341_RED);
  tft.fillRect(100, 50, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
  tft.fillRect(50, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
  tft.fillRect(50, 100, BOXSIZE, BOXSIZE, ILI9341_CYAN);
  tft.fillRect(50, 50, BOXSIZE, BOXSIZE, ILI9341_DARKGREEN);
}
  
void loop()
{
  // See if there's any  touch data for us
  if (!ts.bufferEmpty())
  {   
    // Retrieve a point  
    TS_Point p = ts.getPoint(); 
    // Scale using the calibration #'s
    // and rotate coordinate system
    // surface de contact voulu
    p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
    p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());

 if (( p.y < 70 )&&( p.y > 30)){
  if (( p.x < 40 )&&( p.x > 0 )){
    Serial.println ("Reculer");
  }
 }
 if (( p.y < 70 )&&( p.y > 30 )){
  if (( p.x < 190 )&&( p.x > 150 )){
    Serial.println ("Avancer");
  }
 }
 if (( p.y < 40 )&&( p.y > 0 )){
  if (( p.x < 120 )&&( p.x > 80 )){
    Serial.println ("Gauche");
  }
 }
 if (( p.y < 120 )&&( p.y > 80 )){
  if (( p.x < 120 )&&( p.x > 80 )){
    Serial.println ("Droite");
  }
 }
 if (( p.y < 70 )&&( p.y > 30 )){
  if (( p.x < 110 )&&( p.x > 70 )){
    Serial.println ("Lance");
  }
 }
}

Je pense qu'il faut que j'utilise la commande DigitalWrite afin que lorsque la touche avancer et appuyer le robot avance mais je suis un peu perdu alors si quelqu'un pourrai me mettre sur la bonne voie se serai vraiment sympa ! :slight_smile:

Merci

hello
en vous laissant la responsabilité de savoir si vos codes fonctionnent séparément

testez ceci

//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.
//
//Thanks to Adafruit forums member Asteroid for the original sketch!
//
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>

// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

#define BOXSIZE 40

#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#define Btn 40

boolean RecordOn = false;

int direction_moteur_droite = 7;
int direction_moteur_gauche = 4;
int controle_moteur_droite = 6;
int controle_moteur_gauche = 5;

void setup(void)
{
  Serial.begin(9600);
  tft.begin();
  if (!ts.begin()) { 
    Serial.println("Unable to start touchscreen.");
  } 
  else { 
    Serial.println("Touchscreen started."); 
  }

  tft.fillScreen(ILI9341_BLACK);
  // origin = left,top landscape (USB left upper) 
  tft.fillRect(0 ,50 ,BOXSIZE ,BOXSIZE, ILI9341_RED);
  tft.fillRect(100, 50, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
  tft.fillRect(50, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
  tft.fillRect(50, 100, BOXSIZE, BOXSIZE, ILI9341_CYAN);
  tft.fillRect(50, 50, BOXSIZE, BOXSIZE, ILI9341_DARKGREEN);


  int i;
  for (i=4;i<=7;i++){
    pinMode(i, OUTPUT); //définit les port 4 à 7 en sortie
  }
  analogWrite(controle_moteur_gauche, 0); // arrêt moteur gauche
  analogWrite(controle_moteur_droite, 0); // arrêt moteur droite
}
  
void loop()
{
  // See if there's any  touch data for us
  if (!ts.bufferEmpty())
  {   
    // Retrieve a point  
    TS_Point p = ts.getPoint(); 
    // Scale using the calibration #'s
    // and rotate coordinate system
    // surface de contact voulu
    p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
    p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());

 if (( p.y < 70 )&&( p.y > 30)){
  if (( p.x < 40 )&&( p.x > 0 )){
    Serial.println ("Reculer");
    moteur(250, LOW, 250, LOW); //Reculer
  }
 }
 if (( p.y < 70 )&&( p.y > 30 )){
  if (( p.x < 190 )&&( p.x > 150 )){
    Serial.println ("Avancer");
    moteur(250, HIGH, 250, HIGH); //Avancer
  }
 }
 if (( p.y < 40 )&&( p.y > 0 )){
  if (( p.x < 120 )&&( p.x > 80 )){
    Serial.println ("Gauche");
    moteur(0, HIGH, 250, HIGH); //Gauche
  }
 }
 if (( p.y < 120 )&&( p.y > 80 )){
  if (( p.x < 120 )&&( p.x > 80 )){
    Serial.println ("Droite");
    moteur(250, HIGH, 0, HIGH); // Droite
  }
 }
 if (( p.y < 70 )&&( p.y > 30 )){
  if (( p.x < 110 )&&( p.x > 70 )){
    Serial.println ("Lance");
  }
 }
}
 void moteur (int moteur_gauche, boolean sens_moteur_gauche, int moteur_droite, boolean sens_moteur_droite)
{
  // définition sens moteur LOW avance, HIGH recule
  digitalWrite(direction_moteur_gauche, sens_moteur_gauche);
  analogWrite(controle_moteur_gauche, moteur_gauche);
  digitalWrite(direction_moteur_droite, sens_moteur_droite);
  analogWrite(controle_moteur_droite, moteur_droite);
}

Bonjour, merci de ta réponse j'ai modifié très légèrement se que tu as fais et sa marche merci beaucoup.
Le seul problème est que quand j'appuie sur une touche le robot s'active correctement cependant il ne s'arrête jamais, je pourrai créer un bouton arrêt mais je préférerai qu'une fois la touche relâché il s'arrête d'avancer.
J'ai essayé d'utiliser la fonction "else" pour en gros dire "si toucher pas pressé moteur robot 0" mais je ne doit pas la placé au bon endroit si tu as une solution je suis preneur

Voici le code fonctionnel :

#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>

// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

#define BOXSIZE 40

#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#define Btn 40

#include <Servo.h>

int PIN_SVERSE_1    = 3;               //--Pin affecte servo moteur 1
int PIN_SVERSE_2    = 1;               //--Pin affecte servo moteur 2

Servo mySERVE1;                        //--servo moteur 1
Servo mySERVE2;    

boolean RecordOn = false;

int direction_moteur_droite = 7;
int direction_moteur_gauche = 2;
int controle_moteur_droite = 6;
int controle_moteur_gauche = 5;

void moteur (int moteur_gauche, boolean sens_moteur_gauche, int moteur_droite, boolean sens_moteur_droite)
{
  // définition sens moteur LOW avance, HIGH recule
  digitalWrite(direction_moteur_gauche, sens_moteur_gauche);
  analogWrite(controle_moteur_gauche, moteur_gauche);
  digitalWrite(direction_moteur_droite, sens_moteur_droite);
  analogWrite(controle_moteur_droite, moteur_droite);
}

void setup(void)
{
  Serial.begin(9600);
  tft.begin();
  if (!ts.begin()) { 
    Serial.println("Unable to start touchscreen.");
  } 
  else { 
    Serial.println("Touchscreen started."); 
  }

  tft.fillScreen(ILI9341_BLACK);
  // origin = left,top landscape (USB left upper) 
  tft.fillRect(0 ,50 ,BOXSIZE ,BOXSIZE, ILI9341_RED);
  tft.fillRect(100, 50, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
  tft.fillRect(50, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
  tft.fillRect(50, 100, BOXSIZE, BOXSIZE, ILI9341_CYAN);
  tft.fillRect(50, 50, BOXSIZE, BOXSIZE, ILI9341_DARKGREEN);

  int i;
  for (i=2;i<=7;i++){
    pinMode(i, OUTPUT); //définit les port 4 à 7 en sortie
  }
  analogWrite(controle_moteur_gauche, 0); // arrêt moteur gauche
  analogWrite(controle_moteur_droite, 0); // arrêt moteur droite
  pinMode(PIN_SVERSE_1, OUTPUT);          //--Le PIN est en sortie
pinMode(PIN_SVERSE_2, OUTPUT);          //--Le PIN est en sortie

mySERVE1.attach(PIN_SVERSE_1);
mySERVE2.attach(PIN_SVERSE_2);

  //--On met les angles à 0
mySERVE1.write(90);
mySERVE2.write(60);
}

  
void loop()
{
 
  // See if there's any  touch data for us
  if (!ts.bufferEmpty())
  {   
    // Retrieve a point  
    TS_Point p = ts.getPoint(); 
    // Scale using the calibration #'s
    // and rotate coordinate system
    // surface de contact voulu
    p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
    p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());

  


 if (( p.y < 70 )&&( p.y > 30)){
  if (( p.x < 40 )&&( p.x > 0 )){
    Serial.println ("Reculer");
    moteur(250, LOW, 250, LOW); //Reculer
  } 
 }
 if (( p.y < 70 )&&( p.y > 30 )){
  if (( p.x < 190 )&&( p.x > 150 )){
    Serial.println ("Avancer");
    moteur(250, HIGH, 250, HIGH); //Avancer
 }
 }
 if (( p.y < 40 )&&( p.y > 0 )){
  if (( p.x < 120 )&&( p.x > 80 )){
    Serial.println ("Gauche");
    moteur(0, HIGH, 250, HIGH); //Gauche
  }
 }
 if (( p.y < 120 )&&( p.y > 80 )){
  if (( p.x < 120 )&&( p.x > 80 )){
    Serial.println ("Droite");
    moteur(250, HIGH, 0, HIGH); // Droite
  }
 }
 
 if (( p.y < 70 )&&( p.y > 30 )){
  if (( p.x < 110 )&&( p.x > 70 )){
    Serial.println ("Lance");
  }
 }
}
  
    
    
}

Merci

hello
j'ai modifié la loop

le prg me semble plus simple et plus facile à décrypter

#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>

// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

#define BOXSIZE 40

#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#define Btn 40

#include <Servo.h>

int PIN_SVERSE_1    = 3;               //--Pin affecte servo moteur 1
int PIN_SVERSE_2    = 1;               //--Pin affecte servo moteur 2

Servo mySERVE1;                        //--servo moteur 1
Servo mySERVE2;    

boolean RecordOn = false;

int direction_moteur_droite = 7;
int direction_moteur_gauche = 2;
int controle_moteur_droite = 6;
int controle_moteur_gauche = 5;

void moteur (int moteur_gauche, boolean sens_moteur_gauche, int moteur_droite, boolean sens_moteur_droite)
{
  // définition sens moteur LOW avance, HIGH recule
  digitalWrite(direction_moteur_gauche, sens_moteur_gauche);
  analogWrite(controle_moteur_gauche, moteur_gauche);
  digitalWrite(direction_moteur_droite, sens_moteur_droite);
  analogWrite(controle_moteur_droite, moteur_droite);
}

void setup(void)
{
  Serial.begin(9600);
  tft.begin();
  if (!ts.begin()) { 
    Serial.println("Unable to start touchscreen.");
  } 
  else { 
    Serial.println("Touchscreen started."); 
  }

  tft.fillScreen(ILI9341_BLACK);
  // origin = left,top landscape (USB left upper) 
  tft.fillRect(0 ,50 ,BOXSIZE ,BOXSIZE, ILI9341_RED);
  tft.fillRect(100, 50, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
  tft.fillRect(50, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
  tft.fillRect(50, 100, BOXSIZE, BOXSIZE, ILI9341_CYAN);
  tft.fillRect(50, 50, BOXSIZE, BOXSIZE, ILI9341_DARKGREEN);

  int i;
  for (i=2;i<=7;i++){
    pinMode(i, OUTPUT); //définit les port 4 à 7 en sortie
  }
  analogWrite(controle_moteur_gauche, 0); // arrêt moteur gauche
  analogWrite(controle_moteur_droite, 0); // arrêt moteur droite
  pinMode(PIN_SVERSE_1, OUTPUT);          //--Le PIN est en sortie
pinMode(PIN_SVERSE_2, OUTPUT);          //--Le PIN est en sortie

mySERVE1.attach(PIN_SVERSE_1);
mySERVE2.attach(PIN_SVERSE_2);

  //--On met les angles à 0
mySERVE1.write(90);
mySERVE2.write(60);
}

  
void loop()
{
 
  // See if there's any  touch data for us
  if (!ts.bufferEmpty())
  {   
    // Retrieve a point  
    TS_Point p = ts.getPoint(); 
    // Scale using the calibration #'s
    // and rotate coordinate system
    // surface de contact voulu
    p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
    p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());

//****************************************//p.y entre 30 et 70
 if (( p.y < 70 )&&( p.y > 30))
    {
    if (( p.x < 40 )&&( p.x > 0 ))        //p.x entre 0 et 40
        {
        Serial.println ("Reculer");
        moteur(250, LOW, 250, LOW);       //Reculer
        } 
 
     if (( p.x < 190 )&&( p.x > 150 ))    //p.x entre 150 et 190
        {
         Serial.println ("Avancer");
         moteur(250, HIGH, 250, HIGH);    //Avancer
        }
     if (( p.x < 110 )&&( p.x > 70 ))     //p.x entre 70 et 110
        {
        Serial.println ("Lance");
        }        
    }
    else//****************************************//p.x entre 80 et 120
    {
    if (( p.x < 120 )&&( p.x > 80 ))       
      {
        if (( p.y < 40 )&&( p.y > 0 ))      //p.y entre 0 et 40
          {
          Serial.println ("Gauche");
          moteur(0, HIGH, 250, HIGH);      //Gauche
          }
          if (( p.x < 120 )&&( p.x > 80 ))
          {//p.x entre 80 et 120
          Serial.println ("Droite");
          moteur(250, HIGH, 0, HIGH);      // Droite
          }
        }
      
      }
   }
   else//*****aucune touche actionnee, le buffer est vide***********
      {
      analogWrite(controle_moteur_gauche, 0); // arrêt moteur gauche
      analogWrite(controle_moteur_droite, 0); // arrêt moteur droite
      }
 }