PWM without extender

With Spider and 4.1 is it possible to use PWMOutput without an extender module?
I’m just dimming an LED and the examples with the extender module work fine.
However I see no point in having the extender module for simply accessing a P socket, for example socket 11, pin 9.

The Extender module just gives you access to the pins you are using. Without the Extender, the pin in the socket still toggles with the PWM signal you send. So the challenge you would then face is how do you connect up your LED to that toggling pin without an Extender - if you can figure that out then you’ll be fine ! For example you could cut a gadgeteer cable and solder onto the wires direct; the Extender module is just nice for doing this kind of thing cleanly.

I’m using the physical module to extend the connections but why does it have to be included in the Designer?
I have other examples using DigitalOutput (as MFConsoleApplications not Gadgeteer) where this is not a problem.

I would have thought this code snippet would be ok for driving an LED on pin 9 of socket 11:

GT.Socket socket11 = GT.Socket.GetSocket(11, true, null, null);
PWMOutput MyRedLED = new PWMOutput(socket11, socket11.PWM9, null);

(These arguments were all displayed by Intellisense.)

Error 1 The best overloaded method match for ‘Gadgeteer.Interfaces.PWMOutput.PWMOutput(Gadgeteer.Socket, Gadgeteer.Socket.Pin, Gadgeteer.Modules.Module)’ has some invalid arguments

Error 2 Argument 2: cannot convert from ‘Gadgeteer.Socket.SocketInterfaces.PWM’ to ‘Gadgeteer.Socket.Pin’

Try…

GT.Socket socket11 = GT.Socket.GetSocket(11, true, null, null);
PWMOutput MyRedLED = new PWMOutput(socket11, Socket.Pin.Nine, null);

I get: “Error 1 The name ‘Socket’ does not exist in the current context”

In reference to the 2nd argument of the 2nd line.

This must be do-able and I’m messing up something simple.

@ Nantizle - try socket11.Pin.Nine

Thanks ianlee74 and Justin. I tried your suggestions but it only moved the syntax error around to another spot on that line. That got me to pay closer attention to the Intellisense popups so I appreciate the feedback.

Weird that Intellisense offers up these options but they don’t work. Then I noticed it “suggested” something and that worked. Here it is:

 PWMOutput MyRedLED = new PWMOutput(socket11, Gadgeteer.Socket.Pin.Nine, null);

So it works but I need to try and understand this better … or just get used to using the extender syntax without necessarily having the extender module in place.

The GT in @ ianlee74’s code example is just an alias for the Gadgeteer namespace. So if you didn’t have a using statement already that set up that alias, that might be why you were seeing errors with that syntax, and not when you used the full namespace.

One useful Visual Studio tip…if you’re typing a class name and you see Intellisense show a red squiggly under the name, try typing Ctrl+. while the cursor is still in or at the end of the class name. Visual Studio should offer to include any necessary [em]using[/em] statement if you are already referencing the required assemblies. Can be quite a time-saver.

Thanks for the VS tip!

I did have the statement “using GT = Gadgeteer;” as well as a pile of references.

One way or another this forum always leads me to a fix.

Reading through the “Plain NETMF on Gadgeteer” tutorial I came across this one line version which also works:

GT.Socket.SocketInterfaces.PWM MyRedLED = GT.Socket.GetSocket(11, true, null, null).PWM9;

More syntax to study.

Summary of the two methods that work in case it helps other newbies.
This example is for an LED on pin 9 of socket 11, Spider & 4.1.


GT.Socket socket11 = GT.Socket.GetSocket(11, true, null, null);
PWMOutput MyRedLED = new PWMOutput(socket11, GT.Socket.Pin.Nine, null);

GT.Socket.SocketInterfaces.PWM MyRedLED = GT.Socket.GetSocket(11, true, null, null).PWM9;

Why not use the extender driver but without using the extender?