/*
 * Function: servo()
 * Author: J-N
 *
 * Apply power to "pwm" to bring the "actual" analog reading
 * until it matches "target".  Matching is defined as being
 * within "deadband" of the same.
 * The values "power_up" and "power_down" are used to drive
 * "pwm" in the direction to bring "actual" closer to "target".
 * When "actual" and "target" match, this function returns true.
 */
#include "servo.h"
#include <stdio.h>

int servo(unsigned char *pwm, unsigned char target,
	  unsigned char actual,unsigned char deadband,
	  unsigned char power_up, unsigned char power_down)
{
  *pwm = 127;
        if(actual <= target - deadband)
        {
                *pwm = power_up;
                return 0;
        }
      
        if(actual >= target + deadband)
        {
                *pwm = power_down;
                return 0;
        }
	return 1;
}

