Skip to content

Commit 250e2f3

Browse files
committed
add a 'getting started' example and include it in the README
1 parent c2a5cca commit 250e2f3

5 files changed

Lines changed: 93 additions & 7 deletions

File tree

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,38 @@ dotnet add package Smdn.Devices.MCP2221
9696
Nextly, write your codes. The simplest code, blinking the LEDs connected to the GP pins is like below.
9797

9898
```cs
99-
using System;
100-
using System.Threading;
99+
using System.Device.Gpio;
100+
101101
using Smdn.Devices.MCP2221;
102102

103+
// Find and open the first MCP2221 device connected to the USB port.
103104
using var device = MCP2221.Open();
104105

105-
// configure GP0-GP3 as GPIO output
106+
// Configure the GP pins (GP0-GP3) as GPIO output.
106107
device.GP0.ConfigureAsGPIO(PinMode.Output);
107108
device.GP1.ConfigureAsGPIO(PinMode.Output);
108109
device.GP2.ConfigureAsGPIO(PinMode.Output);
109110
device.GP3.ConfigureAsGPIO(PinMode.Output);
110111

111-
// blink GP0-GP3
112+
// Blink the configured GPIO pins.
112113
foreach (var gp in device.GPs) {
113-
Console.WriteLine($"blink {gp.PinDesignation}");
114+
Console.WriteLine($"Blinking {gp.PinDesignation}");
114115

115116
for (var n = 0; n < 10; n++) {
116-
gp.SetValue(false); Thread.Sleep(100);
117-
gp.SetValue(true); Thread.Sleep(100);
117+
// Set the pin output to Low (logic 0)
118+
gp.SetValue(false);
119+
Thread.Sleep(100);
120+
121+
// Set the pin output to High (logic 0)
122+
gp.SetValue(true);
123+
Thread.Sleep(100);
118124
}
119125
}
120126
```
121127

128+
[See the actual action in the video](https://www.youtube.com/watch?v=MnIunESm71E)
129+
[![See the actual action in the video](https://img.youtube.com/vi/MnIunESm71E/mqdefault.jpg)](https://www.youtube.com/watch?v=MnIunESm71E)
130+
122131
For detailed instructions, including wiring of the devices and parts, see [blink example](examples/Smdn.Devices.MCP2221/blink-csharp) page.
123132

124133
More examples can be found in following examples directory.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Device.Gpio;
2+
3+
using Smdn.Devices.MCP2221;
4+
5+
// Find and open the first MCP2221 device connected to the USB port.
6+
using var device = MCP2221.Open();
7+
8+
// Configure the GP pins (GP0-GP3) as GPIO output.
9+
device.GP0.ConfigureAsGPIO(PinMode.Output);
10+
device.GP1.ConfigureAsGPIO(PinMode.Output);
11+
device.GP2.ConfigureAsGPIO(PinMode.Output);
12+
device.GP3.ConfigureAsGPIO(PinMode.Output);
13+
14+
// Blink the configured GPIO pins.
15+
//
16+
// This example assumes an LED is connected to each pin.
17+
// See this code in action in the YouTube video:
18+
// https://www.youtube.com/watch?v=MnIunESm71E
19+
foreach (var gp in device.GPs) {
20+
Console.WriteLine($"Blinking {gp.PinDesignation}");
21+
22+
for (var n = 0; n < 10; n++) {
23+
// Set the pin output to Low (logic 0)
24+
gp.SetValue(false);
25+
Thread.Sleep(100);
26+
27+
// Set the pin output to High (logic 0)
28+
gp.SetValue(true);
29+
Thread.Sleep(100);
30+
}
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2026 smdn <smdn@smdn.jp>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
<Project Sdk="Microsoft.NET.Sdk">
6+
7+
<PropertyGroup>
8+
<OutputType>Exe</OutputType>
9+
<TargetFramework>net10.0</TargetFramework>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<Nullable>enable</Nullable>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Smdn.Devices.MCP2221" Version="*" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Getting started
2+
3+
## How to run the example
4+
Execute the command `dotnet run`.
5+
6+
## Notes
7+
The code in this example is to be included in the README of the NuGet package.
8+
9+
Therefore, the content should be simple and ready to run.
10+
Also, the copyright and license information for individual files should be omitted for convenience of appearing on NuGet.org.
11+
12+
## Copyright and License Information
13+
- [Program.cs](Program.cs): Copyright © 2026 [smdn](mailto:smdn@smdn.jp), [MIT License](../../LICENSE.txt)

src/Smdn.Devices.MCP2221/Smdn.Devices.MCP2221.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ This library enables you to control **MCP2221/MCP2221A**'s GPIO, I2C interface,
102102
<PackageReadmeFileContent><![CDATA[# $(PackageId) $(PackageVersion)
103103
$(Description)
104104
105+
106+
## Usage
107+
This is an example of switching the output of each pin on GP0-GP3 of the MCP2221 at specific intervals to make the connected LED blink.
108+
109+
以下のコードは、MCP2221のGP0-GP3の各ピンの出力を一定間隔で切り替え、接続されているLEDを点滅させる例です。
110+
111+
```cs
112+
$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)..\..\examples\$(PackageId)\GettingStarted\Program.cs').TrimEnd())
113+
```
114+
115+
The entire code is available on the [GitHub repository]($(RepositoryUrl)/tree/main/examples/$(PackageId)/).
116+
117+
完全なコードは[GitHubリポジトリ]($(RepositoryUrl)/tree/main/examples/$(PackageId)/)を参照してください。
118+
119+
105120
## Contributing
106121
This project welcomes contributions, feedbacks and suggestions. You can contribute to this project by submitting [Issues]($(RepositoryUrl)/issues/new/choose) or [Pull Requests]($(RepositoryUrl)/pulls/) on the [GitHub repository]($(RepositoryUrl)).
107122

0 commit comments

Comments
 (0)