This example assumes you have a servo with the following characteristics, which happen to be typical:
movement between 0 and 180 degrees
pulse period of 20 ms
minimum pulse length of 0.5 ms
maximum pulse length of 2.5 ms
You need to check if those values match your hardware, since forcing it to go outside its specified operating range can damage the servo. A damaged servo in turn has the potential to damage your Android Things device. The example ServoController class consists of two methods, setup() and setPosition():
You can discover pin names that support PWM on your device as follows:
In order to make your servo swinging forever between 80 degrees and 100 degrees, you can simply use the following code:
You can compile and deploy all of the above code without actually hooking any servo motors to the computing device. For the wiring, refer to your computing device pinout chart (e.g. a Raspberry Pi 3 pinout chart is available here).
Then you need to hook your servo to Vcc, Gnd, and signal.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0