Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object > ElectronicSpeedController
Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.Motors
Assembly ElectronicSpeedController.dll

Syntax

public class ElectronicSpeedController

Constructors

ElectronicSpeedController(IPin, Frequency)

Creates a new ElectronicSpeedController object.

Declaration
public ElectronicSpeedController(IPin pwmPin, Frequency frequency)

Parameters

Type Name Description
IPin pwmPin

A PWM capable pin.

Frequency frequency

The frequency of the PWM signal. All ESCs should support 50Hz, but some support much higher frequencies for finer-grained speed control.

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

ElectronicSpeedController(IPwmPort)

Initializes an electronic speed controller on the specified device pin, at the specified frequency.

Declaration
public ElectronicSpeedController(IPwmPort port)

Parameters

Type Name Description
IPwmPort port

The IPwmPort that will drive the ESC.

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

Properties

ArmingPulseDuration

The pulse duration, in milliseconds, necessary to "arm" the ESC. Default value is 0.5ms.

Declaration
public float ArmingPulseDuration { get; set; }

Property Value

Type Description
float

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

Frequency

Frequency (in Hz) of the PWM signal. The default is 50Hz. Increase for higher quality ESCs that allow higher frequency PWM control signals.

Declaration
public Frequency Frequency { get; }

Property Value

Type Description
Frequency

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

IsDisposed

Gets a value indicating whether the object has been disposed.

Declaration
public bool IsDisposed { get; }

Property Value

Type Description
bool

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

Power

Gets or sets the power of the ESC, in the range of 0.0 to 1.0.

Declaration
public float Power { get; set; }

Property Value

Type Description
float

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

Methods

Arm()

Sends a 0.5ms pulse to the motor to enable throttle control.

Declaration
public void Arm()

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

CalculateDutyCycle(float, Frequency)

Calculates the appropriate duty cycle of a PWM signal for the given pulse duration and frequency.

Declaration
protected float CalculateDutyCycle(float pulseDuration, Frequency frequency)

Parameters

Type Name Description
float pulseDuration

The duration of the target pulse in milliseconds.

Frequency frequency

The frequency of the PWM signal.

Returns

Type Description
float

A duty cycle value expressed as a percentage between 0.0 and 1.0.

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

CalculatePulseDuration(float)

Returns a pulse duration in milliseconds for the given power, assuming that the allowed power band is between 1ms and 2ms.

Declaration
protected float CalculatePulseDuration(float power)

Parameters

Type Name Description
float power

A value between 0.0 and 1.0 representing the percentage of power, with 0.0 = 0% and 1.0 = 100%.

Returns

Type Description
float

A pulse duration in milliseconds for the given power.

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

Dispose()

Driver for Electronic Speed Controllers (ESCs) typically used to control motors via PWM signals. To use, you generally have to calibrate the ESC through the following steps:

  1. Depower the ESC, set the power to the intended maximum point (e.g., 1.0).
  2. Power the ESC and wait for "happy tones" to indicate a good power supply, followed by possibly two beeps to indicate the max power limit set.
  3. Set the ESC power to the intended minimum power point (e.g., 0.0), and the ESC should provide one beep for every LiPo cell (3.7V) of power supplied, followed by a long beep.
  4. Optionally, for some ESCs, arm it by calling the Arm() method, which will drop the power below 0.0.
Declaration
public void Dispose()

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub

Dispose(bool)

Dispose of the object

Declaration
protected virtual void Dispose(bool disposing)

Parameters

Type Name Description
bool disposing

Is disposing

Remarks

ElectronicSpeedController
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.ElectronicSpeedController
float frequency = 50f;
const float armMs = 0.5f;
const float powerIncrement = 0.05f;

ElectronicSpeedController esc;
RotaryEncoderWithButton rotary;

public MeadowApp()
{
    Initialize();
    DisplayPowerOnLed(esc.Power);
}

void Initialize()
{
    Console.WriteLine("Initialize hardware...");

    //==== rotary encoder
    rotary = new RotaryEncoderWithButton(Device, Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += Rotary_Rotated;
    rotary.Clicked += (s, e) => {
        Console.WriteLine($"Arming the device.");
        _ = esc.Arm();
    }; ;

    //==== Electronic Speed Controller
    esc = new ElectronicSpeedController(Device, Device.Pins.D02, frequency);

    Console.WriteLine("Hardware initialized.");
}

private void Rotary_Rotated(object sender, Meadow.Peripherals.Sensors.Rotary.RotaryChangeResult e)
{
    esc.Power += (e.Direction == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Console.WriteLine($"New Power: {esc.Power * (float)100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)Map(power, 0f, 1f, 0f, 255f);
    int b = (int)Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

float Map(float value, float fromSource, float toSource, float fromTarget, float toTarget)
{
    return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}

Sample project(s) available on GitHub

|

Code Example

private readonly Frequency frequency = new Frequency(50, Frequency.UnitType.Hertz);
private const float armMs = 0.5f;
private const float powerIncrement = 0.05f;
private ElectronicSpeedController esc;
private RotaryEncoderWithButton rotary;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    rotary = new RotaryEncoderWithButton(Device.Pins.D07, Device.Pins.D08, Device.Pins.D06);
    rotary.Rotated += RotaryRotated;
    rotary.Clicked += (s, e) =>
    {
        Resolver.Log.Info($"Arming the device.");
        esc.Arm();
    }; ;

    esc = new ElectronicSpeedController(Device.Pins.D02, frequency);

    Resolver.Log.Info("Hardware initialized.");

    return base.Initialize();
}

private void RotaryRotated(object sender, RotaryChangeResult e)
{
    esc.Power += (e.New == RotationDirection.Clockwise) ? powerIncrement : -powerIncrement;
    DisplayPowerOnLed(esc.Power);

    Resolver.Log.Info($"New Power: {esc.Power * 100:n0}%");
}

/// <summary>
/// Displays the ESC power on the onboard LED as full red @ `100%`,
/// blue @ `0%`, and a proportional mix, in between those speeds.
/// </summary>
/// <param name="power"></param>
private void DisplayPowerOnLed(float power)
{
    // `0.0` - `1.0`
    int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f);
    int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f);

    var color = Color.FromRgb(r, 0, b);
}

public override Task Run()
{
    DisplayPowerOnLed(esc.Power);

    return base.Run();
}

Sample project(s) available on GitHub