This is just defining a Gadgeteer socket object, using socket 9.
var analogIn = new GT.Interfaces.AnalogInput(socket, GT.Socket.Pin.Five, null);
this creates a VAR object (not a “real” type). It happens to be a Gadgeteer AnalogInput type, and is the Gadgeteer way of defining an AnalogIn pin based on an existing socket.
If you look at the Gadgeteer references to AnalogInput, http://www.netmf.com/gadgeteer/docs/gadgeteercore/html/42848af9-1785-a78d-68ce-c453e3e2c310.htm you will see that there’s no scaling method; the scaling you refer to later is related to the GHI AnalogIn implementation. So you can implement your own scaling function that uses either the voltage or proportion value that the Gadgeteer type exposes.
There’s also another method you want to look at when using GetSocket, and that is ReservePin. Here’s an example of how you could achieve what you want without using Gadgeteer’s AnalogInput:
AnalogIn anaIn = new AnalogIn((AnalogIn.Pin)socket.ReservePin(Gadgeteer.Socket.Pin.Five, null));
anaIn.SetLinearScale(0, 10);
Hi Brett,
Thanks for your reply. So does that mean that I can either of these approaches (Interfaces.AnalogInput or AnalogIn)?
What is the difference between them? There is not enough documentation on this as far as I could find.
What I was wondering about here:
If I use (AnalogIn) do I need to define a socket? Do I need to refer to the actual pin number in the processor here and not in the socket?
If I use (Interfaces.AnalogInput) do I understand you correctly that I don’t need to set a scale in forehand? In this case do I just make scale division later after I read my Analog value?
If there is a working example that could help a lot.
The last code I added requires you to use GetSocket.
There’s lots of examples and documentation, but I just suspect that you’re still early in your understanding of how all these things work together and how you would put these pieces all together - unfortunately you might have picked on a “curly” one to start
Fundamentally, either approach allows you to read an analog input in your code. I assume that’s what you want to do, right?
The difference is that one is using the Gadgeteer interface, and this means that it might be more “hardware agnostic” than the GHI specific implementation. What is the right way to do this? Well, the Gadgeteer method works perfectly when you have lots of other Gadgeteer modules. If you aren’t using Gadgeteer, then there’s no need to use Gadgeteer (adding more references consumes memory unnecessarily). But if you want to write one piece of code and have it work on multiple Gadgeteer devices irrespective of whose hardware platform it is, you might want to choose the Gadgeteer approach.
Getting back onto how to pick up the info about this. Have you been through the references at http://www.ghielectronics.com/support/dotnet-micro-framework as well as the tutorials ? There’s a lot of information there, but by starting on this knowledge early you should start to understand some of those more foundation concepts to start - they’re well worth the effort to go through them.
We’re all happy to help here, just let us know more about what you’re trying to achieve so we know how we might better guide you.
Thank you Brett and Justin,
Brett, I did search for answers in documentation but couldn’t find the explanation that you provided for example. I had seen the example in the link you provided. I couldn’t locate a socket initiation in it. I’ll do some more searching.
Justin, I am using a spider. I would like to read the output signal from a pressure sensor. Appreciate it.
@ TJag, my only point about the examples was that if you have spent time going through them, you’d start to understand the [em]why[/em] behind the code. Also by looking at the API references you’d get an understanding of how the Gadgeteer interface differs and whether there was something in the way you wanted to use the sensor reading that made it better to be used one way of the other.
Y = resultant
X = Input Value
M = linear rate Y2-Y1 / X2-X1
C = Offset
// Where result could be a scaled value between min max values of say 0-250 deg c
Result = ((Raw Value) * ((ScaledMax - ScaledMin) / (InputMax - InputMin))) + Offset;