Fablab ado > mbot : telecommande

par Antoine

Nous avons commencer a travailler avec la télécommande :

voici un premier code :
dans ce code nous utilisons les flèches Up et Down pour faire avancer ou reculer le robot :

pour vérifier le fonctionnement : ouvrir le moniteur série (dans outil)

#include "MeMCore.h"

#define ledPin 13
#define leftLed 1
#define rightLed 0

#define NONE 0

// declaration des moteurs
MeDCMotor motG(M1); //Motor1 is Left Motor
MeDCMotor motD(M2); //Motor2 is Right Motor

int speedMot=100;
int oldMove=NONE;

MeRGBLed led(0, 30);

//declaration de la telecommande
MeIR ir;

uint32_t value = ir.value;


void setup()
{
 // put your setup code here, to run once:

ir.begin();
Serial.begin(9600);
}
               
void teleco()
{
   if(ir.decode())
   {
     uint32_t value = ir.value;
     //Serial.print("Raw Value: ");
     //Serial.println(value);
     value = value >> 16 & 0xff;
     //Serial.print("Button Code: ");
     //Serial.println(value);
     Serial.print("Button: ");
     switch(value)
       {
           case IR_BUTTON_A:
               Serial.println("A");
               break;
           case IR_BUTTON_B:
               Serial.println("B");
               break;
           case IR_BUTTON_C:
               Serial.println("C");
               break;
           case IR_BUTTON_D:
               Serial.println("D");
               break;
           case IR_BUTTON_E:
               Serial.println("E");
               break;
           case IR_BUTTON_F:
               Serial.println("F");
               break;
           case IR_BUTTON_SETTING :
               Serial.println("Setting");
               break;
           case IR_BUTTON_LEFT:
               Serial.println("Left");      
               break;
           case IR_BUTTON_RIGHT:
               Serial.println("Right");          
               break;
           case IR_BUTTON_UP:
               Serial.println("Up");
               motG.run(-speedMot); //Motor1 (Left)  forward is -negative
               motD.run(speedMot);  //Motor2 (Right) forward is +positive
               delay(200);
               motG.stop(); //Stop Motor1
               motD.stop(); //Stop Motor1
               delay(100);
               break;
           case IR_BUTTON_DOWN:
               Serial.println("Down");
               motG.run(speedMot); //Motor1 (Left)  forward is -negative
               motD.run(-speedMot);  //Motor2 (Right) forward is +positive
               delay(500);
               motG.stop(); //Stop Motor1
               motD.stop(); //Stop Motor1
               delay(100);
               break;
           case IR_BUTTON_0:
               Serial.println("0");
               break;
           case IR_BUTTON_1:
               Serial.println("1");
               break;
           case IR_BUTTON_2:
               Serial.println("2");
               break;
           case IR_BUTTON_3:
               Serial.println("3");                
               break;
           case IR_BUTTON_4:
               Serial.println("4");                
               break;
           case IR_BUTTON_5:
               Serial.println("5");                
               break;
           case IR_BUTTON_6:
               Serial.println("6");                
               break;
           case IR_BUTTON_7:
               Serial.println("7");                
               break;
           case IR_BUTTON_8:
               Serial.println("8");                
               break;
           case IR_BUTTON_9:
               Serial.println("9");                
               break;
           default:
               motG.stop(); //Stop Motor1
               motD.stop(); //Stop Motor1
               delay(500);
               break;
       }
       delay(100);
   }
 
}

void loop()
{
 teleco();
}

A vous d’ajouter d’autres fonctions en fonction des touches !