1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00
elua/romfs/dualpwm.lua
James Snyder 271dcc15e1 Enable PWM support for lpc17xx/mbed.
Note: pin functions need to be configured on this platform for output to go to
a given pin.
2010-02-20 00:27:33 +00:00

40 lines
932 B
Lua

-- Control LED intensity with PWM on two channels
local pwmid1, pwmid2, tmrid
if pd.board() == 'MOD711' or pd.board() == 'ET-STM32' then
pwmid1, pwmid2, tmrid = 0, 1, 3
elseif pd.board() == 'MBED' then
pwmid1, pwmid2, tmrid = 1, 2, 0
mbed.pio.configpin(mbed.pio.LED1, 2, 0, 0)
mbed.pio.configpin(mbed.pio.LED2, 2, 0, 0)
else
print( pd.board() .. " not supported by this example" )
return
end
print "Control LED with PWM (fade up/down)"
print "Press any key to exit"
local crtduty, incr = 10, 5
tmr.start( tmrid )
pwm.setup( pwmid1, 50000, crtduty )
pwm.setup( pwmid2, 50000, 100 - crtduty )
pwm.start( pwmid1 )
pwm.start( pwmid2 )
while uart.getchar( 1, 0 ) == "" do
if crtduty == 95 or crtduty == 5 then
incr = -incr
end
crtduty = crtduty + incr
pwm.setup( pwmid1, 50000, crtduty )
pwm.setup( pwmid2, 50000, 100 - crtduty )
tmr.delay( tmrid, 50000 )
end
pwm.stop( pwmid1 )
pwm.stop( pwmid2 )