Controlling 2 DC motor from Matlab with Arduino

I am trying to learn how to control my 2 DC motor from Matlab to Arduino. The Arduino is connected with a Quadruple Half H-Bridge.
So far this is what I got:
a=arduino('COM14')
a.pinMode(2,'OUTPUT');
a.pinMode(3,'OUTPUT');
a.pinMode(4,'OUTPUT');
a.pinMode(5,'OUTPUT');
a.pinMode(9,'OUTPUT');
a.pinMode(10,'OUTPUT')
Pin 2,3 and 9 is for the Motor X. Pin 4,5 and 10 is for Motor Y. Pin 9 enables Motor X while Pin 10 enables Motor Y. I know that to drive both of them is to use this:
a.digitalWrite(9, 1);
a.digitalWrite(2, 1);
a.digitalWrite(3, 0);
a.digitalWrite(10, 1);
a.digitalWrite(4, 1);
a.digitalWrite(5, 0);
or this (this one turns it the opposite direction):
a.digitalWrite(2, 0);
a.digitalWrite(3, 1);
a.digitalWrite(9, 1);
a.digitalWrite(4, 0);
a.digitalWrite(5, 1);
a.digitalWrite(10, 1);
I can control it manually if I just write it down on the command line, but I can't seem to get how to make it run the same on a written script.

Answers (0)

Communities

More Answers in the  Power Electronics Control

Categories

Products

Asked:

on 4 Mar 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!