张高兴的 Windows 10 IoT 开发笔记:使用 MAX7219 驱动数码管

This is a Windows 10 IoT Core project on the Raspberry Pi 2/3, coded by C#.

GitHub:https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/MAX7219_7Segment

Image

Connect

  • DIN - MOSI
  • CS - CS0
  • CLK - SCLK
  • VCC - 5V
  • GND - GND

Reference

https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/MAX7219/Reference

What Contains

In MAX7219.cs file

/// <summary>
/// Initialize MAX7219
/// </summary>
public async Task InitializeAsync();
/// <summary>
/// Set Register Data and Print
/// </summary>
/// <param name="index">Segment index, range from 0 to 7</param>
/// <param name="val">Printed data</param>
/// <param name="isDecimal">Does it show Decimal Point (Only for DecodeMode is Digit7)</param>
public void SetSegment(int index, byte value, bool isDecimal = false);
/// <summary>
/// Set MAX7219 Decode Mode
/// </summary>
/// <param name="mode">Mode</param>
public void SetDecode(DecodeMode mode);
/// <summary>
/// Set Brightness
/// </summary>
/// <param name="val">In range 0-16</param>
public void SetIntensity(int val);
/// <summary>
/// Test Display
/// </summary>
/// <param name="mode">Mode</param>
public void DisplayTest(DisplayTestMode mode);
/// <summary>
/// Set MAX7219 Power
/// </summary>
/// <param name="mode">Mode</param>
public void SetPower(PowerMode mode);
/// <summary>
/// Clear the Segment
/// </summary>
public void Clear();
/// <summary>
/// Cleanup
/// </summary>
public void Dispose();

How to Use

  • First, you need to create a MAX7219 object. After that you should call InitializeAsync() to initialize.
MAX7219 led = new MAX7219(0, DecodeMode.Digit7);
await led.InitializeAsync();
led.SetIntensity(5);
  • Secondly
for (int i = 0; i < 8; i++)
{
    led.SetSegment(i, (byte)i);
}
  • If you want to close the sensor, call Dispose().
led.Dispose();
posted @   张高兴  阅读(472)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示