Pioneer600 LED1(D1) 的控制

通过控制gpio的设备文件的读写来控制LED1(物理 37 脚,BCM 26 脚)

DigitalPinner是对GPIO的基本抽象,其实现以下接口:

type DigitalPinner interface {
	// Export exports the pin for use by the operating system
	Export() error
	// Unexport unexports the pin and releases the pin from the operating system
	Unexport() error
	// Direction sets the direction for the pin
	Direction(string) error
	// Read reads the current value of the pin
	Read() (int, error)
	// Write writes to the pin
	Write(int) error
}
  • 初始化
led.pin.Export()
led.pin.Direction(driver.OUT)
  • 灯亮
led.pin.Write(driver.LOW)
  • 灯灭
led.pin.Write(driver.HIGH)
  • 基本的调用逻辑如下:
业务             设备            驱动
cmd/main.go ---> dev/led.go ---> driver/gpio

源码

github 源码目录