Skip to content

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.

  • 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. Create an empty GameObject, for example RGB.
  2. Add SerialInputBridge > PWM Output Helper three times.
  3. Set their Pin to 3, 6 and 10 (red, green, blue).
  1. Add three UI > Slider objects, each with Min 0 and Max 1. Label them R, G and B.
  2. 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.

Point your AnalogInputEvent for A0 at one helper’s SetValue01. Turning the potentiometer now dims that color.

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.