Playing with the Beginners Guide and have a problem with FEZ_Pin.PWM.LED

Hello all,

I’m just playing with PWM examples in the Guide and have a problem with FEZ_Pin.PWM.LED.

I expected that FEZ_Pin.Digital.LED is the same led as FEZ_Pin.PWM.LED or im totally wrong?
When i’m running the example on page 55 (the fading led) the led light is not changing at all.

btw i have updated my FEZ to the last firmware so that can’t be the issue is it?

It’s a bug in the example :wink: Or a typo ?

The (bad) line is this one :

byte duty = 1;

At this place, duty should be set to at least 11 or else the test “if (duty > 90 || duty < 10)” will make duty oscillating between 1 and 2 : 1 2 1 2 1 2 1 2
It will never be greater than 2, hence the led staying “off”.

I have written a small pieze of code to read a POT-value and dim the led:

    public class Program
        public static void Main()
            byte duty = 1;
            FEZ_Components.POT pot = new FEZ_Components.POT(FEZ_Pin.AnalogIn.An0);
            PWM pwm = new PWM((PWM.Pin)FEZ_Pin.PWM.Di10);
            while (true)
                duty = Convert.ToByte(pot.GetPosition().ToString());
                pwm.Set(10000, duty);


Why this line ?

duty = Convert.ToByte(pot.GetPosition().ToString());

Shouldn’t it be something like this ? :

duty = (byte)pot.GetPosition();

I don’t understand why you convert to string and then convert it immediately back to byte ?! That’s without taking into account that such calls are a bit time consuming.

thankyou Bec à Fuel,

that was exact the problem.
I think the wetter here is playing with my mind.

You’re welcome :slight_smile:

indeed, wrote it quick, my bad…:wink:

We will update the book. Thanks

fixed, thanks

Thank you too. It will prevent other messages like this one :wink: