The project has been updated to include a LED dimmer as a PWM example.
The additional code included in the updated project source on Codeplex follows:
In MainPage.xaml:
Add two more rows to the <grid> element:
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
Then add a TextBlock and Slider for those rows:
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Height="34" Margin="10,10.333,0,-44.333" Grid.Row="9" TextWrapping="Wrap" Text="PWM: LED Dimmer" VerticalAlignment="Top" Width="273"/>
In MainPage.cs in the class declarations:
//Dimmer (Use Pin 10):
private const int PWM_PIN = 10;
In OnConnected()
//Dimmer:
arduino.pinMode(PWM_PIN, PinMode.PWM);
PWM value range from 0 to 255. In the Slider's XAML, the max value is set to 255. At the bottom of the class insert:
private void slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
byte val = (byte) slider.Value;
arduino.analogWrite(PWM_PIN, val);
}
Connect Pin 10 to a LED as per Blinky. AND AWAY YOU GO. As you slide the slider the intensity of the LED will vary.