6 – ServoOutputHelper component
ServoOutputHelper points one servo at an angle. It has two methods:
| Method | Input | What it does |
|---|---|---|
| SetAngle(float) | Degrees, 0–180 | Points the servo at that angle. Values outside 0–180 are clamped. |
| SetValue01(float) | 0–1 | Moves between Min Angle (0) and Max Angle (1). Fits straight onto AnalogInputEvent and UI sliders. |
Before you start
Section titled “Before you start”- Wire the servo with its signal on D3.
- In Set Up Arduino, set D3 to Servo Out and write it into your profile.
1. Add the component
Section titled “1. Add the component”- Create an empty GameObject, for example
Servo. - Add Component > SerialInputBridge > Servo Output Helper.
- Set Pin to 3.
- Optional: narrow Min Angle and Max Angle if your mechanism shouldn’t use the full 0–180° range.
2. Turn it with the knob
Section titled “2. Turn it with the knob”- On your AnalogInputEvent for A0, click + under On Value Changed.
- Drag in the
ServoGameObject and choose ServoOutputHelper > SetValue01 under Dynamic float.
Press Play and turn the potentiometer. The servo follows.
3. Or drive it from a UI slider
Section titled “3. Or drive it from a UI slider”Add a UI > Slider (Min 0, Max 1) and point its On Value Changed at SetValue01 (Dynamic float). For degrees, set the slider to 0–180 and use SetAngle instead.
4. Or type an angle
Section titled “4. Or type an angle”The package includes an example script, ServoAngleOut, in Assets/SerialInputBridge/fromtutorialvideos/. It reads a number from a TextMeshPro input field and calls SetAngle.
- Add a UI > Input Field - TextMeshPro.
- Add ServoAngleOut to a GameObject. Drag the
ServoGameObject into Servo and the input field into Angle Input Field. - On the input field, under On End Edit (String), click +, drag in the ServoAngleOut GameObject and choose ServoAngleOut > SetAngleFromInput under Dynamic string.
Press Play, type 90 and press Enter.