function setMotorSpd(speed_volts,direction_volts,handle)
Vmax = 3.2;
digital_output_arr = zeros(1,8);

if speed_volts > Vmax
    speed_volts = Vmax;
end
if speed_volts < 0
    speed_volts = 0;
end

binary_out = (255 * speed_volts)/Vmax;
digital_output_str = dec2bin(binary_out);

len_arr = length(digital_output_arr);
len_str = length(digital_output_str);

for i = 1:len_str
    temp_str = digital_output_str( len_str+1 - i );
    temp_num = str2num(temp_str);
    digital_output_arr( len_arr+1 - i ) = temp_num;
end

% Send speed digital output to Phidgets board
for i = 1:len_arr
    digital_line = len_arr - i;
    state = digital_output_arr(i);

    % Flip ones and zeros
    if state == 0
        state = 1;
    else
        state = 0;
    end
    
    calllib('phidget21', 'CPhidgetInterfaceKit_setOutputState',handle,digital_line,state);
end

% Send direction digital output to Phidgets board
if direction_volts == 1
    calllib('phidget21', 'CPhidgetInterfaceKit_setOutputState',handle,15,0);
    calllib('phidget21', 'CPhidgetInterfaceKit_setOutputState',handle,14,1);
elseif direction_volts == -1
    calllib('phidget21', 'CPhidgetInterfaceKit_setOutputState',handle,15,1);
    calllib('phidget21', 'CPhidgetInterfaceKit_setOutputState',handle,14,0);
else
    calllib('phidget21', 'CPhidgetInterfaceKit_setOutputState',handle,15,1);
    calllib('phidget21', 'CPhidgetInterfaceKit_setOutputState',handle,14,1);
end    


