Piloter les moteurs

La bibliothèque NXShield permet de contrôler finement le comportement de blocs moteurs LEGO (jusqu’à 4 moteurs).

/***********************************************************************
LEGO-NXshield
Pilotage des moteurs
*********************************************************************** */

#include <Wire.h>
#include <NXShield.h>

NXShield nxshield;

void setup() {
    long rotations = 2; 

    nxshield.init( SH_HardwareI2C );

    nxshield.bank_a.motorReset();
    nxshield.bank_b.motorReset();

    nxshield.bank_a.motorRunRotations(SH_Motor_1, 
                     SH_Direction_Forward,          // avant
                     SH_Speed_Medium,
                     rotations, 
                     SH_Completion_Wait_For,        // mode synchrone
                     SH_Next_Action_BrakeHold);

    nxshield.bank_a.motorRunRotations(SH_Motor_1, 
                     SH_Direction_Reverse,          // arrière
                     20,
                     rotations, 
                     SH_Completion_Dont_Wait ,      // mode asynchrone
                     SH_Next_Action_BrakeHold);

    nxshield.bank_b.motorRunRotations(SH_Motor_1, 
                     SH_Direction_Forward, 
                     80,
                     rotations, 
                     SH_Completion_Wait_For,
                     SH_Next_Action_BrakeHold);

    nxshield.bank_b.motorRunRotations(SH_Motor_1, 
                     SH_Direction_Reverse, 
                     100,
                     rotations, 
                     SH_Completion_Wait_For,
                     SH_Next_Action_BrakeHold);

}

void loop() {
}

Plus de détails : méthode .motorRunRotations

Vous aimerez aussi...

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.