功能
待办
// Look over all frame buffer devices in `/dev/` for one of Sense Hat.
// Use default orientation `.up`
guard let senseHat = SenseHat() else {
fatalError("Can't initialise Raspberry Pi Sense Hat")
}
参数 orientation
可用于其他方向,例如 SenseHat(orientation: .left)
。参数 frameBufferDevice
可用于指定帧缓冲区设备,例如 SenseHat(frameBufferDevice: "/dev/fb0")
。两个参数可以同时使用:SenseHat(frameBufferDevice: "/dev/fb0", orientation: .down)
。
参数 orientation 定义 LED 矩阵的顶部在哪里。以下是用不同方向显示相同字符 "1"
的示例
.up |
.left |
.right |
.down |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
senseHat.set(color: .red) // sets all LEDs of matrix to red
senseHat.set(color: .black) // sets all LEDs of matrix to black, literally turns them off
senseHat.set(color: .black) // clear
senseHat.set(x: 0, y: 0, color: .white) // set most top left LED to white using function syntax
senseHat[7, 7] = .green // set most bottom right LED to green using subscript syntax
坐标 x
和 y
应属于 0..<7
范围。
senseHat.show(character: Character("A"), color: .blue)
senseHat.show(character: Character("π"), color: .yellow, background: .blue)
senseHat.show(string: "Hello! ", secPerChar: 0.5, color: .yellow, background: .blue)
senseHat.orientation = .left
senseHat.show(string: "Απόλλων ", secPerChar: 0.5, color: .red, background: .darkGray)
senseHat.orientation = .right
senseHat.show(string: "ここからそこまで ", secPerChar: 0.5, color: .white, background: .brown)
senseHat.orientation = .down
senseHat.show(string: "Fußgängerübergänge ", secPerChar: 0.5, color: .white, background: .purple)
if let h = senseHat.humidity() {
let strH = String(format: "%.1lf", h.H_rH)
senseHat.show(string: "Humidity \(strH)% rH ", secPerChar: 0.5, color: .yellow, background: .black)
let strT = String(format: "%.1lf", h.T_DegC)
senseHat.show(string: "Temperature \(strT)ºC", secPerChar: 0.5, color: .yellow, background: .black)
} else {
print("Cannot read humidity sensor")
}
if let p = senseHat.pressure() {
let strP = String(format: "%.1lf", p.P_hPa)
let strT = String(format: "%.1lf", p.T_DegC)
senseHat.show(string: "Pressure \(strP) hPa ", secPerChar: 0.5, color: .yellow, background: .black)
senseHat.show(string: "Temperature \(strT)ºC", secPerChar: 0.5, color: .yellow, background: .black)
} else {
print("Cannot read pressure sensor")
}
遗憾的是,Raspberry Pi Sense Hat 的数据手册或程序员手册不存在,或者我未能找到。这里有一些实用链接
Rgb565
中打包成两个字节;