Exemple #1
0
// SetAngle sets the servo angle.
func (s *Servo) SetAngle(angle int) error {
	us := util.Map(int64(angle), 0, 180, int64(s.Minus), int64(s.Maxus))

	glog.V(1).Infof("servo: given angle %v calculated %v us", angle, us)

	return s.PWM.SetMicroseconds(int(us))
}
Exemple #2
0
// RunAt sets the engine speed. Valid values at [0-100]
func (e *engine) RunAt(speed int) error {
	if speed < minSpeed {
		speed = minSpeed
	}
	if speed > maxSpeed {
		speed = maxSpeed
	}

	value := util.Map(int64(speed), minSpeed, maxSpeed, minAnalogValue, maxAnalogValue)

	return e.pwm.SetAnalog(byte(value))
}
Exemple #3
0
// SetAnalog is a convinience method which allows easy manipulation of the PWM
// based on a (0-255) range value.
func (p *pwmChannel) SetAnalog(value byte) error {
	offTime := util.Map(int64(value), 0, 255, 0, pwmControlPoints-1)
	return p.d.SetPwm(p.channel, 0, int(offTime))
}
Exemple #4
0
func (p *pwmPin) SetAnalog(value byte) error {
	duty := util.Map(int64(value), 0, 255, 0, int64(p.period))
	return p.SetDuty(int(duty))
}