Bonjour à tous,
je bloque sur mon projet Arduino avec mon robot mini tank V2, j'aimerais lui faire exécuter plusieurs action avec sa télécommande mais je n'arrive pas a assembler plusieurs action (comme reculer ou avancer). il m'indique que le croquis est bon mais quand j'appuis sur le bouton correspondant cela ne fonctionne pas. pouvez vous m'aider sil vous plait ?
[code]
/* keyestudio Mini Tank Robot V2
lesson 6.2
IRremote
http://www.keyestudio.com
*/
#define ML_Ctrl 13 //define the direction control pin of left motor
#define ML_PWM 11 //define the PWM control pin of left motor
#define MR_Ctrl 12 //define direction control pin of right motor
#define MR_PWM 3 // define the PWM control pin of right motor
#include <IRremoteTank.h>
int RECV_PIN = A0;//define the pin of IR receiver as A0
int PWM_PIN = 11; //define the pin of PWM
int a=0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
pinMode(ML_Ctrl, OUTPUT);//define direction control pin of left motor as output
pinMode(ML_PWM, OUTPUT);//define PWM control pin of left motor as output
pinMode(MR_Ctrl, OUTPUT);//define direction control pin of right motor as output.
pinMode(MR_PWM, OUTPUT);//define the PWM control pin of right motor as output
Serial.begin(9600);
irrecv.enableIRIn(); // Initialize the IR receiver
pinMode(PWM_PIN,OUTPUT);//set PWM_pin to OUTPUT
}
void loop() {
if (irrecv.decode(&results)) {
if(results.value==0xFFC23D &a==0) // according to the above key value, press“↑”on remote control , LED will be controlled
{
digitalWrite(PWM_PIN,HIGH);//LED will be on
a=0;
//left
digitalWrite(ML_Ctrl,LOW);//set the direction control pin of left motor to LOW
analogWrite(ML_PWM,200);//set the PWM control speed of left motor to 200
digitalWrite(MR_Ctrl,HIGH);//set the direction control pin of right motor to HIGH
analogWrite(MR_PWM,200);//set the PWM control speed of right motor to 200
}
else if(results.value==0xFFC23D &a==1) //press again
{
digitalWrite(PWM_PIN,LOW);//LED will go off
a=1;
irrecv.resume(); //receive the next value
}
}
}
//******************************************************
S’il vous plaît prenez vite en compte et mettez en application les recommandations listées dans « Les bonnes pratiques du Forum Francophone” en commençant par éditer votre post et rajouter les balises de code.
Un lien vers votre tank, le diagramme du montage etc seraient utiles aussi…
Rajoutez des print pour voir si vos touches de votre télécommande sont bien reçues,
Vérifiez aussi le câblage en détail ainsi que l’alimentation (partagez un schéma et des détails)
pour les touches de ma télécommande c'est déjà fait j'utilise dans la barre d'outils moniteur série et tous et bien reçu, et les câblages et l'alimentation sont parfaites
Comme le préconise @J-M-L, un Serial.println(results, HEX); bien placé peut aider.
if (irrecv.decode(&results)) {
Serial.println(results, HEX);
if(results.value==0xFFC23D &a==0) // according to the above key value, press“↑”on remote control , LED will be controlled
Tu pourra contrôler la justesse de la réception.
Dans la formule if(results.value==0xFFC23D &a==0) si la condition est ET a == 0, il faut orthographier &&a==0
Je ne peut pas tester ton programme, mais il me semble que le traitement de la variable a n'est pas juste, dans la condition où il y a a=0; ce devrait être a=1; et la condition où il y a
a=1; ce devrait être a=0;
La ligne irrecv.resume(); devrait être comme ci-dessous:
{
digitalWrite(PWM_PIN,LOW);//LED will go off
a=1;
}
irrecv.resume(); //receive the next value