Before assembling a robot or something using some motors, you should preset the angles of motors first.

This small tip shows how to preset some motors using PHPoC Blue.


Source Code


[Source code - task0.php]
PHP Code:
<?php

if(_SERVER("REQUEST_METHOD"))
    exit; 
// avoid php execution via http request

include "/lib/sd_340.php";
include 
"/lib/sn_tcp_ws.php";

define("PWM_PERIOD"20000); // 20000us (20ms)
define("WIDTH_MIN"771);
define("WIDTH_MAX"2193);

ht_pwm_setup(0WIDTH_MINPWM_PERIOD"us");

function 
servo_set_angle($angle)
{
    if(
$angle 0)
        
$angle 0;

    if(
$angle 180)
        
$angle 180;

    
$width WIDTH_MIN + (int)round((WIDTH_MAX WIDTH_MIN) * $angle 180.0);

    if((
$width >= WIDTH_MIN) && ($width <= WIDTH_MAX))
        
ht_pwm_width(0$widthPWM_PERIOD);    
}

servo_set_angle(90) ; // change your desired angle here

while(1)
{

}

?>