Hello proconrpi.
First robsonj wrote a create readme.md file which can be found on his git hub here.That said I don’t mind walking you through a simple tutorial. I am assuming you know how to deploy a Universal Windows Application on your PI and just need help with using the GrovePi Win10 library. If that’s not the case let me know.
In your “Driver” project you should see a project called “Simple Driver.cs”. In this file you can see several quick samples of sensors.
Go ahead and clear out the “Run” method for now so it looks like this (paste bin for readability): http://pastebin.com/dP5iSKsn
private readonly IBuildGroveDevices _deviceFactory = DeviceFactory.Build;
public void Run(IBackgroundTaskInstance taskInstance)
{
}
the “_deviceFactory” is what we will use to build all of our Grove Sensors. Currently only the sensors in the starter kit are supported (and a few extras)
Alright, lets start with something easy. Lets build an led, grab its state, and turn it on. Plug in your Grove LED into pin D2 then add the following code : http://pastebin.com/t93Bmnu6
public void Run(IBackgroundTaskInstance taskInstance)
{
//Build the LED sensor that is
//plugged into the GrovePi at port D2:
var led = _deviceFactory.Led(Pin.DigitalPin2);
//Grab the sensors current state. At this point
//it should = SensorStatus.Off
var currentState = led.CurrentState;
//Turn LED on
led.ChangeState(SensorStatus.On););
}
In the code above we build an LED sensor, grab its current state, and turn it on. Note that many sensors function the same way as the LED including the Buzzer, Relay, SoundSensor, and ButtonSensor.
To show this lets build a simple button. plug in your Grove button into D2 and replace your code with the following: http://pastebin.com/W8bPCHgM
public void Run(IBackgroundTaskInstance taskInstance)
{
//Build the button sensor that is
//plugged into the GrovePi at pin D2:
var button = _deviceFactory.ButtonSensor(Pin.DigitalPin2);
//Break out of while loop on button press
while (true)
{
//Try catch to prevent error from reading
//too quickly
try
{
if (button.CurrentState == SensorStatus.On)
break;
}
catch (Exception)
{
throw;
}
}
}
Many of our methods can be chained together. For example you can build a sensor and read its value from the same line. Here on example : http://pastebin.com/EwehYWnG
public void Run(IBackgroundTaskInstance taskInstance)
{
//This is the same as...
var ultraSonicSensor = _deviceFactory.UltraSonicSensor(Pin.DigitalPin2);
var measurementInCentimeters = ultraSonicSensor.MeasureInCentimeters();
//This
var measurementInCentimetersChain = _deviceFactory.UltraSonicSensor(Pin.DigitalPin2).MeasureInCentimeters();
}
This is great if you simply need to get/set a value once and never use it again. Or if you want to build a sensor and act on said sensor all in one line.
You can use intellisense on _deviceFactory to get a full list of supported sensors so far. Let us know if there is a sensor you are looking for that’s not on the list!
Hope this helps some.