summaryrefslogtreecommitdiff
path: root/Origin/user-code/servo/scilab/servo_pot.sce
blob: 524e1d29d7f5206941bbc4dc548fb8f47eeed711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Connect the Arduino at port 2
ok = open_serial(1,2,115200) 

if ok ~= 0 error('Check the serial port and try again');
end

// Attach the motor to pin 9. 1~pin 9, 2~pin 10 
cmd_servo_attach(1,1)

for i=1:40                  //Run for 40 itterations
    p=cmd_analog_in(1,2)    //Read potntiometer value
    p=floor(p*(180/1023))   //Scale Potentiometer value to 0-180
    cmd_servo_move(1,1,p)   //Command the servo motor
    sleep(500)              //sleep for 500 milliseconds
end
close_serial(1);            //To close the connection safely