mirror of
https://github.com/stianeikeland/go-rpio.git
synced 2025-02-02 15:30:36 +01:00
Removing percentage, and fixing example
This commit is contained in:
parent
0ad5c5ccb6
commit
2cd91fb24d
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
A Software Based PWM example by @Ronin11, using the go-rpio library
|
A Software Based PWM example by @Ronin11, using the go-rpio library
|
||||||
|
|
||||||
Toggles a LED on physical pin 19 (mcu pin 10)
|
Toggles a LED on physical pin 10
|
||||||
Connect a LED with resistor from pin 19 to ground.
|
Connect a LED with resistor from pin 10 to ground.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -29,19 +29,20 @@ func main() {
|
||||||
// Unmap gpio memory when done
|
// Unmap gpio memory when done
|
||||||
defer rpio.Close()
|
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 := rpio.CreateSofwarePWM(pin, 2000, 0, 32)
|
||||||
|
|
||||||
pwm.Start()
|
pwm.Start()
|
||||||
|
defer pwm.Stop()
|
||||||
// five times smoothly fade in and out
|
// five times smoothly fade in and out
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
for i := uint32(0); i < 32; i++ { // increasing brightness
|
for i := uint32(0); i < 32; i++ { // increasing brightness
|
||||||
pwm.SetDutyCycle(i, 32)
|
pwm.SetDutyCycle(i, 32)
|
||||||
time.Sleep(time.Second/32)
|
time.Sleep(time.Second/32)
|
||||||
}
|
}
|
||||||
for i := uint8(99); i > 0; i-=3 { // decreasing brightness
|
for i := uint32(32); i > 0; i-- { // decreasing brightness
|
||||||
pwm.SetDutyCyclePercentage(i)
|
pwm.SetDutyCycle(i, 32)
|
||||||
time.Sleep(time.Second/32)
|
time.Sleep(time.Second/32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pwm.Stop()
|
|
||||||
}
|
}
|
9
rpio.go
9
rpio.go
|
@ -581,15 +581,6 @@ func (swPwm *SoftwarePWM) SetDutyCycle(dutyLen uint32, cycleLen uint32){
|
||||||
swPwm.cycleLen = cycleLen
|
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
|
//Sets the frequency of the software PWM
|
||||||
func (swPwm *SoftwarePWM) SetFreq(freq uint32){
|
func (swPwm *SoftwarePWM) SetFreq(freq uint32){
|
||||||
swPwm.freq = freq
|
swPwm.freq = freq
|
||||||
|
|
Loading…
Reference in New Issue
Block a user