Since | Origin / Contributor | Maintainer | Source |
---|---|---|---|
2014-12-22 | Zeroday | Zeroday | pwm.c |
Quit PWM mode for the specified GPIO pin.
pwm.close(pin)
pin
1~12, IO index
nil
Get selected PWM frequency of pin.
pwm.getclock(pin)
pin
1~12, IO index
number
PWM frequency of pin
Get selected duty cycle of pin.
pwm.getduty(pin)
pin
1~12, IO index
number
duty cycle, max 1023
Set PWM frequency. Note: Setup of the PWM frequency will synchronously change other setups as well if there are any. Only one PWM frequency can be allowed for the system.
pwm.setclock(pin, clock)
pin
1~12, IO indexclock
1~1000, PWM frequency
nil
Set duty cycle for a pin.
pwm.setduty(pin, duty)
pin
1~12, IO indexduty
0~1023, pwm duty cycle, max 1023 (10bit)
nil
-- D1 is connected to green led
-- D2 is connected to blue led
-- D3 is connected to red led
pwm.setup(1, 500, 512)
pwm.setup(2, 500, 512)
pwm.setup(3, 500, 512)
pwm.start(1)
pwm.start(2)
pwm.start(3)
function led(r, g, b)
pwm.setduty(1, g)
pwm.setduty(2, b)
pwm.setduty(3, r)
end
led(512, 0, 0) -- set led to red
led(0, 0, 512) -- set led to blue.
Set pin to PWM mode. Only 6 pins can be set to PWM mode at the most.
pwm.setup(pin, clock, duty)
pin
1~12, IO indexclock
1~1000, pwm frequencyduty
0~1023, pwm duty cycle, max 1023 (10bit)
nil
-- set pin index 1 as pwm output, frequency is 100Hz, duty cycle is half.
pwm.setup(1, 100, 512)
PWM starts, the waveform is applied to the GPIO pin.
pwm.start(pin)
####Parameters
pin
1~12, IO index
nil
Pause the output of the PWM waveform.
pwm.stop(pin)
pin
1~12, IO index
nil