Once i try to deploy Microsoft.SPOT.Hardware.PWM assembly with Mountaineer Ethernet… i got an exception when i run my program!
Anymody knows the cause?
Once i try to deploy Microsoft.SPOT.Hardware.PWM assembly with Mountaineer Ethernet… i got an exception when i run my program!
Anymody knows the cause?
Have you loaded latest SDK and latest firmware?
Do you have microdoft QFE2? Check again please.
No QFE1 because i want to use gadgeteer… and seems not “supported” by QFE2… even if… i’m wondering… it’s just a Managed Layer… so why not?
Anyway… using a plain vanilla microframework console app works… and i’m able to modulate the on board LED with i color i want! but… when i try to reference from a gadgeteer application doesn’t work!!!
Where do you see that QFE2 doesn’t support gadgeteer? It does
Here:
http://www.mountaineer.org/resources/netmf-4-2-qfe2/
Warning: At this time, the Gadgeteer libraries have not yet been tested with QFE2. So you should only move to QFE2 if you work directly with the “plain vanilla” NETMF APIs, and do not use the Gadgeteer APIs. Thus Gadgeteer is not supported at the moment (support is planned for NETMF 4.3).
no comment @ Gus? (SORRY FOR THAT!!) any idea?? it explode UNDER this auto generated code
//Important to initialize the Mainboard first
Mainboard = new Mountaineer.Gadgeteer.MountaineerEth();
…and this is in the constructor of “Program” for a Gadgeteer application
I didn’t know that! PWM was added in qfe2 IIRC. Can you please post your complete code?
I’m just using this:
Microsoft.SPOT.Hardware.PWM
and i found under QFE1 installation!
Exactly! i tryed to update the Mountaineer eth to QFE2 and now i got “This mainboard installer was not correctly set up it doesnt provide a compatible assembly for .NET Microframework version 4.2”… da da da daaaaaaan
Ok I got things mixed up then That was analog out that was added on QFE2 not PWM.
Please post the code so we can try on our end or ask Oberon for help.
Here is the code.
Now i’ve updated to QFE2 but no changes…
Anyway there is something weird on the assignement of PWM channel for the blue component of the on board led.
Initializing it into a static constructor wasn’t liked… now it WORKS!
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Gadgeteer;
namespace G2Tech.Gadgeteer.MountaineerLed
{
/// <summary>
/// Board RGB Led
/// </summary>
public class BoardRGBLed
{
#region Private Fields
private static bool _initialized = false;
private static Microsoft.SPOT.Hardware.PWM _ledR, _ledG, _ledB;
private static Color _setColor;
private static Color _actualColor;
private static Timer _blinkingTimer = null;
private static bool[] _blinkPattern = null;
private static int _blinkSlot = 0;
private static Timer _fadingTimer = null;
private static bool _fadingBlackToLight = true;
private static int _fadingStep = 0;
private const int _fadingSteps = 20;
#endregion
#region Internal Methods
private static void initialize()
{
if (!_initialized)
{
_ledR = new PWM(G2Tech.Gadgeteer.MountaineerLed.MountaineerHardware.PwmRed, 1000, 0, false);
_ledG = new PWM(G2Tech.Gadgeteer.MountaineerLed.MountaineerHardware.PwmGreen, 1000, 0, false);
_ledB = new PWM(G2Tech.Gadgeteer.MountaineerLed.MountaineerHardware.PwmBlue, 1000, 0, false);
}
}
/// <summary>
/// update PWM to reflect the actual color
/// </summary>
private static void updatePWM(Color color)
{
initialize();
if (color != Color.Black)
{
_ledB.DutyCycle = (double)((float)color.B / (float)255);
_ledG.DutyCycle = (double)((float)color.G / (float)255);
_ledR.DutyCycle = (double)((float)color.R / (float)255);
_ledB.Start();
_ledG.Start();
_ledR.Start();
}
else
{
_ledB.Stop();
_ledG.Stop();
_ledR.Stop();
}
}
/// <summary>
/// blinking timer ticks
/// </summary>
/// <param name="timer"></param>
static void _blinkingTimer_Tick(Timer timer)
{
if (_blinkSlot == _blinkPattern.Length)
{
_blinkSlot = 0;
}
if (_blinkPattern[_blinkSlot])
{
_actualColor = _setColor;
}
else
{
_actualColor = Color.Black;
}
updatePWM(_actualColor);
_blinkSlot++;
}
/// <summary>
/// fading timer ticks
/// </summary>
/// <param name="timer"></param>
static void _fadingTimer_Tick(Timer timer)
{
if (_fadingBlackToLight)
{
_actualColor = HSLHelper.IncreaseLuminescence(_actualColor, 1 / _fadingSteps);
}
else
{
_actualColor = HSLHelper.DecreaseLuminescence(_actualColor, 1 / _fadingSteps);
}
updatePWM(_actualColor);
if (_fadingStep == _fadingSteps)
{
if (_fadingBlackToLight)
_fadingBlackToLight = false;
else
_fadingBlackToLight = true;
}
_fadingStep++;
}
#endregion
#region Public Methods
/// <summary>
/// Set a Static Color
/// </summary>
/// <param name="color"></param>
public static void SetStaticColor(Color color)
{
if (_blinkingTimer != null)
{
_blinkingTimer.Stop();
_blinkingTimer.Tick -= new Timer.TickEventHandler(_blinkingTimer_Tick);
_blinkingTimer = null;
}
_setColor = _actualColor = color;
updatePWM(_setColor);
}
/// <summary>
/// Set a Static Color
/// </summary>
/// <param name="hslColor"></param>
public static void SetStaticColor(HSLColor hslColor)
{
SetStaticColor(hslColor.ToColor());
}
/// <summary>
/// Start to Blink the led
/// </summary>
/// <param name="color"></param>
/// <param name="period"></param>
/// <param name="blinkPattern"></param>
public static void BlinkColor(Color color, int intervalMilliseconds, bool[] blinkPattern)
{
_setColor = color;
if (_blinkingTimer != null)
{
_blinkingTimer.Stop();
_blinkingTimer.Tick -= new Timer.TickEventHandler(_blinkingTimer_Tick);
_blinkingTimer = null;
}
if (blinkPattern == null)
{
_blinkPattern = new bool[] { false, true };
}
_blinkingTimer = new Timer(intervalMilliseconds / _blinkPattern.Length);
_blinkingTimer.Tick+=new Timer.TickEventHandler(_blinkingTimer_Tick);
_blinkingTimer.Start();
}
/// <summary>
/// Start to Blink the led
/// </summary>
/// <param name="hslColor"></param>
/// <param name="period"></param>
/// <param name="blinkPattern"></param>
public static void BlinkColor(HSLColor hslColor, int intervalMilliseconds, bool[] blinkPattern)
{
BlinkColor(hslColor.ToColor(), intervalMilliseconds, blinkPattern);
}
/// <summary>
/// Start to fade color.
/// </summary>
/// <param name="color"></param>
/// <param name="intervalMilliseconds"></param>
/// <param name="blackToLight"></param>
public static void FadeColor(Color color, int intervalMilliseconds, bool blackToLight)
{
ShutOff();
_fadingBlackToLight = blackToLight;
_setColor = color;
_actualColor = Color.Black;
if (_fadingTimer != null)
{
_fadingTimer.Tick += new Timer.TickEventHandler(_fadingTimer_Tick);
_fadingTimer.Stop();
_fadingTimer = null;
}
_fadingTimer = new Timer(intervalMilliseconds / _fadingSteps);
_fadingTimer.Tick += new Timer.TickEventHandler(_fadingTimer_Tick);
_fadingTimer.Start();
}
/// <summary>
/// Shut off the led.
/// </summary>
public static void ShutOff()
{
SetStaticColor(Color.Black);
}
#endregion
#region Public Property
/// <summary>
/// Obtain the Actual Color.
/// </summary>
public static Color ActualColor
{
get
{
return _actualColor;
}
}
#endregion
}
}
Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the
tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)
Thanks for the suggestion i’ll take into account. I’ve already modified my post.
Sorry for that!
in your initialize routine you never set the initialized flag. Each time you set the PWM you repeat the initialization.
Right… was already fixed…