1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/romfs/pwmled.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

36 lines
1007 B
Lua

-- Control LED intensity with PWM
local pwmid, tmrid, ledpin
if pd.board() == 'EK-LM3S8962' or pd.board() == 'EK-LM3S6965' or pd.board() == 'ET-STM32' or pd.board() == 'EAGLE-100' then
pwmid, tmrid = 0, 1
pwm.setclock( pwmid, 25000000 )
elseif pd.board() == 'ELUA-PUC' then
pwmid, tmrid = 7, 0
local psel = cpu.r32( cpu.IO_PINSEL3 )
psel = bit.bor( bit.band( psel, 0xFFFFFCFF ), 0x00000200 )
cpu.w32( cpu.IO_PINSEL3, psel )
elseif pd.board() == 'MBED' then
pwmid, tmrid = 1, 0
mbed.pio.configpin(mbed.pio.LED1, 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( pwmid, 50000, crtduty )
pwm.start( pwmid )
while uart.getchar( 0, 0 ) == "" do
if crtduty == 95 or crtduty == 5 then
incr = -incr
end
crtduty = crtduty + incr
pwm.setup( pwmid, 50000, crtduty )
tmr.delay( tmrid, 50000 )
end
pwm.stop( pwmid )