Improve pwm example

This commit is contained in:
Drahoslav 2018-01-12 15:35:22 +01:00
parent 15b37924a8
commit 1272e9a954

View File

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