7 – PwmOutputHelper component
PwmOutputHelper sets one PWM pin to a level, for dimmable LEDs and motor drivers. It has two methods:
| Method | Input | What it does |
|---|---|---|
| SetValue01(float) | 0–1 | 0 is off, 1 is full. Fits straight onto AnalogInputEvent and UI sliders. |
| SetValueRaw(float) | 0–255 | The raw PWM level. |
Values outside the range are clamped.
Before you start
Section titled “Before you start”- Wire the RGB module to D3, D6 and D10.
- In Set Up Arduino, set D3, D6 and D10 to PWM Out and write them into your profile. Only pins that support PWM on your board offer this role.
1. Add one helper per color
Section titled “1. Add one helper per color”- Create an empty GameObject, for example
RGB. - Add SerialInputBridge > PWM Output Helper three times.
- Set their Pin to 3, 6 and 10 (red, green, blue).
2. Mix colors with sliders
Section titled “2. Mix colors with sliders”- Add three UI > Slider objects, each with Min 0 and Max 1. Label them R, G and B.
- Point each slider’s On Value Changed at the matching helper’s SetValue01 under Dynamic float.
Press Play and drag the sliders to mix colors.
3. Dim with the knob
Section titled “3. Dim with the knob”Point your AnalogInputEvent for A0 at one helper’s SetValue01. Turning the potentiometer now dims that color.
Setting a color from a script
Section titled “Setting a color from a script”using UnityEngine;using Syazmedia.SerialInputBridge;
public class RgbColor : MonoBehaviour{ public PwmOutputHelper red, green, blue;
public void SetColor(Color c) { red.SetValue01(c.r); green.SetValue01(c.g); blue.SetValue01(c.b); }}That’s the full course. Watch it all on the video training playlist.