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 !
Merci