forked from google/periph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
36 lines (31 loc) · 932 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2018 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package tm1637_test
import (
"log"
"periph.io/x/periph/conn/gpio/gpioreg"
"periph.io/x/periph/devices/tm1637"
"periph.io/x/periph/host"
)
func Example() {
// Make sure periph is initialized.
if _, err := host.Init(); err != nil {
log.Fatal(err)
}
clk := gpioreg.ByName("GPIO6")
data := gpioreg.ByName("GPIO12")
if clk == nil || data == nil {
log.Fatal("Failed to find pins")
}
dev, err := tm1637.New(clk, data)
if err != nil {
log.Fatalf("failed to initialize tm1637: %v", err)
}
if err := dev.SetBrightness(tm1637.Brightness10); err != nil {
log.Fatalf("failed to set brightness on tm1637: %v", err)
}
if _, err := dev.Write(tm1637.Clock(12, 00, true)); err != nil {
log.Fatalf("failed to write to tm1637: %v", err)
}
}