I am trying to write a code that will give some sort feedback for the control of a robotic hand. I am working on an Arduino uno, using matlab 2013b. I have setup the matlab with the ArduinoIO Package, and I am able to control the board.
Is there a way to get the servo to stop once the reading on the FSR is high enough? I have tried adding a break function on hopes it would just stop, but it causes the servo returns to the zero position instead.
clc; clear all; close all; a = arduino('com4'); %Assign serial port a.servoAttach(7); %Attach servo to pin 7 count=1; while count==1; %Start loop for angle = 0:10:180; %Angles between 0 and 180 in increments of 10 V=a.analogRead(0) %Analog reading at pin 0 current=a.servoRead(7) %Current angular position of servo 7 a.servoWrite(7, angle) %Move servo 7 to angular position pause(0.5) %Pause for 0.5 seconds to let servo complete action if V>5 %If reading on FSR is above 5 break %Stop loop end end end