Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
Characteristic | Locus |
---|---|
Inheritance | object > PwmLedBarGraph |
Inherited Members | object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() |
Namespace | Meadow.Foundation.Leds |
Assembly | Meadow.Foundation.dll |
Syntax
public class PwmLedBarGraph
Constructors
PwmLedBarGraph(IPin[], Voltage)
Create an LedBarGraph instance for single color LED bar graphs
Declaration
public PwmLedBarGraph(IPin[] pins, Voltage forwardVoltage)
Parameters
Type | Name | Description |
---|---|---|
IPin[] | pins | Array of pins |
Voltage | forwardVoltage | Single forward voltage |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
PwmLedBarGraph(IPin[], Voltage[])
Create an LedBarGraph instance for multi color LED bar graphs
Declaration
public PwmLedBarGraph(IPin[] pins, Voltage[] forwardVoltage)
Parameters
Type | Name | Description |
---|---|---|
IPin[] | pins | Array of pins |
Voltage[] | forwardVoltage | Array of forward voltages |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
PwmLedBarGraph(IPwmPort[], Voltage)
Create an LedBarGraph instance for single color LED bar graphs
Declaration
public PwmLedBarGraph(IPwmPort[] ports, Voltage forwardVoltage)
Parameters
Type | Name | Description |
---|---|---|
IPwmPort[] | ports | Array of Pwm Ports |
Voltage | forwardVoltage | Single forward voltage |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
PwmLedBarGraph(IPwmPort[], Voltage[])
Create an LedBarGraph instance for multi color LED bar graphs
Declaration
public PwmLedBarGraph(IPwmPort[] ports, Voltage[] forwardVoltage)
Parameters
Type | Name | Description |
---|---|---|
IPwmPort[] | ports | Array of ports |
Voltage[] | forwardVoltage | Array of forward voltages |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
Fields
pwmLeds
Array to hold pwm leds for bar graph
Declaration
protected PwmLed[] pwmLeds
Field Value
Type | Description |
---|---|
PwmLed[] |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
Properties
Count
The number of the LEDs in the bar graph
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
Percentage
A value between 0 and 1 that controls the number of LEDs that are activated
Declaration
public float Percentage { get; protected set; }
Property Value
Type | Description |
---|---|
float |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
Methods
GetTopLedForPercentage()
Returns the index of the last LED turned on
Declaration
public int GetTopLedForPercentage()
Returns
Type | Description |
---|---|
int |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
SetBrightness(float)
Set the brightness to the LED bar graph using PWM
Declaration
public Task SetBrightness(float brightness)
Parameters
Type | Name | Description |
---|---|---|
float | brightness | Valid values are from 0 to 1, inclusive |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
SetLed(int, bool)
Set the LED state
Declaration
public Task SetLed(int index, bool isOn)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the LED |
bool | isOn | True for on, False for off |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
SetLedBrightness(int, float)
Set the brightness of an individual LED when using PWM
Declaration
public Task SetLedBrightness(int index, float brightness)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the LED |
float | brightness | Valid values are from 0 to 1, inclusive |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
SetPercentage(float)
Set the percentage of LEDs that are on starting from index 0
Declaration
public Task SetPercentage(float percentage)
Parameters
Type | Name | Description |
---|---|---|
float | percentage | Percentage (Range from 0 - 1) |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartBlink(int, float, float)
Starts a blink animation on an individual LED
Declaration
public Task StartBlink(int index, float highBrightness = 1, float lowBrightness = 0)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the LED |
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartBlink(int, TimeSpan, TimeSpan, float, float)
Starts a blink animation on an individual LED
Declaration
public Task StartBlink(int index, TimeSpan highBrightnessDuration, TimeSpan lowBrightnessDuration, float highBrightness = 1, float lowBrightness = 0)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the LED |
TimeSpan | highBrightnessDuration | The duration the LED stays in high brightness |
TimeSpan | lowBrightnessDuration | The duration the LED stays in low brightness |
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartBlink(float, float)
Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness setting.
Declaration
public Task StartBlink(float highBrightness = 1, float lowBrightness = 0)
Parameters
Type | Name | Description |
---|---|---|
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartBlink(TimeSpan, TimeSpan, float, float)
Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness setting, using the durations provided.
Declaration
public Task StartBlink(TimeSpan highBrightnessDuration, TimeSpan lowBrightnessDuration, float highBrightness = 1, float lowBrightness = 0)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | highBrightnessDuration | On duration. |
TimeSpan | lowBrightnessDuration | Off duration. |
float | highBrightness | High brigtness. |
float | lowBrightness | Low brightness. |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartPulse(int, float, float)
Starts a pulse animation on an individual LED
Declaration
public Task StartPulse(int index, float highBrightness = 1, float lowBrightness = 0.15)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the LED |
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartPulse(int, TimeSpan, float, float)
Starts a pulse animation on an individual LED with the specified pulse cycle
Declaration
public Task StartPulse(int index, TimeSpan pulseDuration, float highBrightness = 1, float lowBrightness = 0.15)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the LED |
TimeSpan | pulseDuration | The pulse animation duration |
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartPulse(float, float)
Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting.
Declaration
public Task StartPulse(float highBrightness = 1, float lowBrightness = 0.15)
Parameters
Type | Name | Description |
---|---|---|
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StartPulse(TimeSpan, float, float)
Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting, using the durations provided.
Declaration
public Task StartPulse(TimeSpan pulseDuration, float highBrightness = 1, float lowBrightness = 0.15)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | pulseDuration | The pulse animation duration |
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StopAnimation()
Stops the LED bar graph when its blinking
Declaration
public Task StopAnimation()
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
StopAnimation(int)
Stops the blinking animation on an individual LED
Declaration
public Task StopAnimation(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the LED |
Returns
Type | Description |
---|---|
Task |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"
ValidateBrightness(float, float)
Validates LED brightness to ensure they're within the range 0 (off) - 1 (full brighness)
Declaration
protected void ValidateBrightness(float highBrightness, float lowBrightness)
Parameters
Type | Name | Description |
---|---|---|
float | highBrightness | The maximum brightness of the animation |
float | lowBrightness | The minimum brightness of the animation |
Remarks
PwmLedBarGraph | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.
The PwmLedBarGraph class allows you to control an led bar graph using PWM ports.
Use the SetLed
method to turn on or off LEDs individually, or assign a value on the Percentage
property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.
Code Example
PwmLedBarGraph pwmLedBarGraph;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
// Using an array of Pins that support PWM (D02 - D13)
IPin[] pins =
{
Device.Pins.D11,
Device.Pins.D10,
Device.Pins.D09,
Device.Pins.D08,
Device.Pins.D07,
Device.Pins.D06,
Device.Pins.D05,
Device.Pins.D04,
Device.Pins.D03,
Device.Pins.D02
};
pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("TestLedBarGraph...");
float percentage = 0;
while (true)
{
Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
for (int i = 0; i < pwmLedBarGraph.Count; i++)
{
await pwmLedBarGraph.SetLed(i, true);
await Task.Delay(100);
await pwmLedBarGraph.SetLed(i, false);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them on using Percentage...");
while (percentage < 1)
{
percentage += 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Turning them off using Percentage...");
while (percentage > 0)
{
percentage -= 0.01f;
await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
await Task.Delay(100);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
await pwmLedBarGraph.StartBlink();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
Resolver.Log.Info("Bar pulsing for 5 seconds...");
await pwmLedBarGraph.StartPulse();
await Task.Delay(5000);
await pwmLedBarGraph.StopAnimation();
await Task.Delay(1000);
await pwmLedBarGraph.SetBrightness(0);
await Task.Delay(1000);
}
}
Sample project(s) available on GitHub
Wiring Example
<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLedBarGraph/PwmLedBarGraph_Fritzing.png"