/// <summary>
        ///   Initializes a new instance of the <see cref="MultiplexedHBridge" /> class.
        /// </summary>
        /// <param name="speedControl">The PWM channel that will control the output power (5KHz max).</param>
        /// <param name="outputShiftRegister">The output shift register that controls the L293D H-Bridge.</param>
        /// <param name="directionA">The bit number in the shift register output that controls IN1 on the L293D.</param>
        /// <param name="directionB">The bit number in the shift register output that controls IN2 on the L293D.</param>
        public MultiplexedHBridge(PWM speedControl,
                                  SerialShiftRegister outputShiftRegister,
                                  ushort directionA,
                                  ushort directionB)
        {
            this.speedControl        = speedControl;
            this.outputShiftRegister = outputShiftRegister;
            this.directionA          = directionA;
            this.directionB          = directionB;
            // For efficiency, initialise some direction transactions ready for use later.
            forwardTransaction = new[]
            {
                new ShiftRegisterOperation(directionA, true),
                new ShiftRegisterOperation(directionB, false)
            };
            reverseTransaction = new[]
            {
                new ShiftRegisterOperation(directionA, false),
                new ShiftRegisterOperation(directionB, true)
            };
            brakeTransaction = new[]
            {
                new ShiftRegisterOperation(directionA, true),
                new ShiftRegisterOperation(directionB, true)
            };
            releaseTransaction = new[]
            {
                new ShiftRegisterOperation(directionA, false),
                new ShiftRegisterOperation(directionB, false)
            };

            InitializeOutputs(); // Ensure the outputs are in a sane, safe state.
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AdafruitV1MotorShield"/> class using the default hardware outputs.
 /// </summary>
 public AdafruitV1MotorShield()
 {
     latch  = new OutputPort(Pins.GPIO_PIN_D12, false);
     enable = new OutputPort(Pins.GPIO_PIN_D7, true);
     data   = new OutputPort(Pins.GPIO_PIN_D8, false);
     clock  = new OutputPort(Pins.GPIO_PIN_D4, false);
     serialShiftRegister = new SerialShiftRegister(enable, clock, data, latch);
 }
Ejemplo n.º 3
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="AdafruitV1MotorShield" /> class.
 /// </summary>
 /// <param name="latch">The latch store register clock pin (STCP).</param>
 /// <param name="enable">The latch output enable pin (OE).</param>
 /// <param name="data">The latch serial data pin (DS).</param>
 /// <param name="clock">The latch shift register clock pin (SHCP).</param>
 public AdafruitV1MotorShield(OutputPort latch, OutputPort enable, OutputPort data, OutputPort clock)
 {
     this.latch          = latch;
     this.enable         = enable;
     this.data           = data;
     this.clock          = clock;
     serialShiftRegister = new SerialShiftRegister(enable, clock, data, latch);
 }