mirror of
https://github.com/elua/elua.git
synced 2025-01-25 01:02:54 +08:00
28 lines
683 B
Lua
28 lines
683 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' then
|
|
pwmid, tmrid = 0, 1
|
|
pwm.setclock( pwmid, 25000000 )
|
|
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 )
|