From 1272e9a95493c8b0d38c40c0b2703469fbe73f82 Mon Sep 17 00:00:00 2001 From: Drahoslav Date: Fri, 12 Jan 2018 15:35:22 +0100 Subject: [PATCH] Improve pwm example --- examples/pwm/pwm.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/pwm/pwm.go b/examples/pwm/pwm.go index 00549a2..215803e 100644 --- a/examples/pwm/pwm.go +++ b/examples/pwm/pwm.go @@ -1,6 +1,6 @@ /* -A PWM example by @Drahoslav7, using the go-rpio library +A PWM example by @Drahoslav7, using the go-rpio library Toggles a LED on physical pin 19 (mcu pin 10) Connect a LED with resistor from pin 19 to ground. @@ -24,15 +24,18 @@ func main() { pin := rpio.Pin(19) pin.Mode(rpio.Pwm) - pin.Freq(60000) + pin.Freq(64000) pin.DutyCycle(0, 32) + // the LED will be blinking at 2000Hz + // (source frequency divided by cycle length => 64000/32 = 2000) + // five times smoothly fade in and out for i := 0; i < 5; i++ { for i := uint32(0); i < 32; i++ { // increasing brightness pin.DutyCycle(i, 32) time.Sleep(time.Second/32) } - for i := uint32(32); i != 0; i-- { // decreasing brightness + for i := uint32(32); i > 0; i-- { // decreasing brightness pin.DutyCycle(i, 32) time.Sleep(time.Second/32) }