From 2cd91fb24dc92cd98399a7be577434582adbd933 Mon Sep 17 00:00:00 2001 From: Ronin11 Date: Mon, 25 Jun 2018 00:08:19 -0600 Subject: [PATCH] Removing percentage, and fixing example --- examples/software pwm/pwm.go | 13 +++++++------ rpio.go | 9 --------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/examples/software pwm/pwm.go b/examples/software pwm/pwm.go index 51d56d0..54fbd1f 100644 --- a/examples/software pwm/pwm.go +++ b/examples/software pwm/pwm.go @@ -2,8 +2,8 @@ A Software Based PWM example by @Ronin11, 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. +Toggles a LED on physical pin 10 +Connect a LED with resistor from pin 10 to ground. */ @@ -29,19 +29,20 @@ func main() { // Unmap gpio memory when done defer rpio.Close() - //Creates the PWM Signal running on the pin, at 2KHz, with a 50 on 50 off cycle. + //Creates the PWM Signal running on the pin, at 2KHz, with a 0% PWM cycle. pwm := rpio.CreateSofwarePWM(pin, 2000, 0, 32) + pwm.Start() + defer pwm.Stop() // five times smoothly fade in and out for i := 0; i < 5; i++ { for i := uint32(0); i < 32; i++ { // increasing brightness pwm.SetDutyCycle(i, 32) time.Sleep(time.Second/32) } - for i := uint8(99); i > 0; i-=3 { // decreasing brightness - pwm.SetDutyCyclePercentage(i) + for i := uint32(32); i > 0; i-- { // decreasing brightness + pwm.SetDutyCycle(i, 32) time.Sleep(time.Second/32) } } - pwm.Stop() } \ No newline at end of file diff --git a/rpio.go b/rpio.go index e751ab0..1978c01 100644 --- a/rpio.go +++ b/rpio.go @@ -581,15 +581,6 @@ func (swPwm *SoftwarePWM) SetDutyCycle(dutyLen uint32, cycleLen uint32){ swPwm.cycleLen = cycleLen } -//Sets the duty cycle percentage of 100 for the sofware PWM -func (swPwm *SoftwarePWM) SetDutyCyclePercentage(percentage uint8){ - if percentage > 100{ - percentage = 100 - } - swPwm.dutyLen = uint32(percentage) - swPwm.cycleLen = 100 -} - //Sets the frequency of the software PWM func (swPwm *SoftwarePWM) SetFreq(freq uint32){ swPwm.freq = freq