Removing percentage, and fixing example

This commit is contained in:
Ronin11 2018-06-25 00:08:19 -06:00
parent 0ad5c5ccb6
commit 2cd91fb24d
2 changed files with 7 additions and 15 deletions

View File

@ -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()
}

View File

@ -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