-
Notifications
You must be signed in to change notification settings - Fork 2
/
pwm_ctrl.go
executable file
·54 lines (40 loc) · 1.1 KB
/
pwm_ctrl.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Go Language Raspberry Pi Interface
(c) Copyright David Thorpe 2018
All Rights Reserved
Documentation http://djthorpe.github.io/gopi/
For Licensing and Usage information, please see LICENSE.md
*/
// Controls PWM on GPIO pins
package main
import (
"fmt"
"os"
// Frameworks
"github.com/djthorpe/gopi"
// Modules
_ "github.com/djthorpe/gopi-hw/sys/gpio"
_ "github.com/djthorpe/gopi-hw/sys/hw"
_ "github.com/djthorpe/gopi-hw/sys/pwm"
_ "github.com/djthorpe/gopi/sys/logger"
)
////////////////////////////////////////////////////////////////////////////////
func mainLoop(app *gopi.AppInstance, done chan<- struct{}) error {
if app.PWM == nil {
return app.Logger.Error("Missing PWM module instance")
}
if err := app.PWM.SetDutyCycle(0, 4); err != nil {
return err
}
fmt.Println(app.PWM)
// Finished
done <- gopi.DONE
return nil
}
////////////////////////////////////////////////////////////////////////////////
func main() {
// Create the configuration, load the spi instance
config := gopi.NewAppConfig("pwm")
// Run the command line tool
os.Exit(gopi.CommandLineTool(config, mainLoop))
}