MATLAB Answers

0

arduino-adafruit shild - readDigitalPin func

Asked by sagie meshulam on 25 Apr 2015
Latest activity Commented on by Geoff Hayes
on 27 Apr 2015
hello, im working on a project Including arduino-adafruit motor shild and a stepper motor.
I attached a hall efect sensor to the arduino (at pin 2) and a magnet to the motor, now i want that the motor will stop moving when the magnet is aboce the senor.
I checked it through matlab and the arduino gets feedback from the sensor just fine. my problem is that when im Writing it on a loop, it wont let me read the pin more than once.
here is the code
a = arduino('com4', 'uno', 'Libraries', 'Adafruit\MotorShieldV2');
switch_check=readDigitalPin(a,2);
sm=Rotate();
for i=1:200
if switch_check==1 %depends on the switch (normally open or normally closed
move(sm,1);
switch_check=readDigitalPin(a,2);%problematic, need to check why!!!
else
disp('the pin is 0')
end
end
and this is what i get after one time the loop is running
"Instrument object OBJ is an invalid object."
i can really use your help thank you

  1 Comment

sagie - which function call is generating this error: the move or the readDigitalPin?

Sign in to comment.

0 Answers