Documentation
¶
Overview ¶
Package led is a driver allowing to control a LED from GPIO pins
Example (Dimmable) ¶
The LED will dim from 0% to 100% to 0% continuously
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) l1.Dimmable() for { for i := 0; i <= 100; i++ { if err := l1.SetBrightness(i); err != nil { log.WithField("error", err).Error("impossible to change LED brightness") } time.Sleep(time.Millisecond * 10) } for i := 100; i >= 0; i-- { if err := l1.SetBrightness(i); err != nil { log.WithField("error", err).Error("impossible to change LED brightness") } time.Sleep(time.Millisecond * 10) } }
Output:
Example (Toggle) ¶
The LED will blink continuously and the current LED status will be displayed as output
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) for { l1.Toggle() time.Sleep(1 * time.Second) state, _ := l1.GetState() fmt.Println(state) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LED ¶
type LED struct {
// contains filtered or unexported fields
}
LED instance
func NewLED ¶
NewLED creates a new LED instance
Example ¶
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() // 18 is one of the PWM compatible GPIO pin on the Raspberry Pi l1 := led.NewLED(18) l1.On()
Output:
func (*LED) Dimmable ¶
func (led *LED) Dimmable()
Dimmable make the LED dimmable
Example ¶
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) l1.Dimmable() // LED is now dimmable (PWM mode is enabled)
Output:
func (*LED) GetState ¶
GetState return the current state of the lED
returns: true for on, off for false
Example ¶
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) l1.On() state, _ := l1.GetState() fmt.Println(state)
Output: true
func (*LED) NonDimmable ¶
func (led *LED) NonDimmable()
NonDimmable make the dimmable LED non dimmable
Example ¶
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) l1.Dimmable() // Here you can use SetBrightness l1.NonDimmable() // LED is not dimmable anymore (PWM mode is disabled)
Output:
func (*LED) Off ¶
func (led *LED) Off()
Off switch off the LED
Example ¶
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) l1.Off()
Output:
func (*LED) On ¶
func (led *LED) On()
On switch on the LED
Example ¶
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) l1.On()
Output:
func (*LED) SetBrightness ¶
SetBrightness set the brightness of the LED
If the LED is connected to a hardware PWM pin, SetBrightness will use hardware PWM If the LED is connected to a non PWM pin, SetBrightness will use a software emulated PWM
Example ¶
err := rpio.Open() if err != nil { os.Exit(1) } defer rpio.Close() l1 := led.NewLED(18) l1.Dimmable() // set LED brightness to 50% of its maximum value if err := l1.SetBrightness(50); err != nil { log.WithField("error", err).Error("impossible to change LED brightness") }
Output:
Click to show internal directories.
Click to hide internal directories.