I am trying to make a LED , according to a switch posistion :
pos 1 turn LED off
pos 2 turn LED on
pos 3 turn LED blink
It is no problem turning the led on or off ... ofcourse but making it blink with a delay of 1 sec is difficult with LUA.!!
I can use Arduino C++ with messageport to realize this, but prefer to use AM LUA only.
Anybody got an idea??
Blinking LED
Re: Blinking LED
http://siminnovations.com/wiki/index.ph ... _API#Timer
When the switch comes on, call a timer to turn it off, and have that timer call it’s own timer to turn it back on, which calls its own timer, so on and so forth
@Corjan Also somehow in my own stupidity I also reported this thread instead of replying to it, so please ignore that
When the switch comes on, call a timer to turn it off, and have that timer call it’s own timer to turn it back on, which calls its own timer, so on and so forth
@Corjan Also somehow in my own stupidity I also reported this thread instead of replying to it, so please ignore that
Re: Blinking LED
There are more ways to do this, but this one might be the easiest to understand.
The timer_stop at position 1 should be enough in theory, but I've added it to position 0 as well, it's good to be sure that it stopped.
The timer_stop at position 1 should be enough in theory, but I've added it to position 0 as well, it's good to be sure that it stopped.
Code: Select all
status_led = hw_output_add("My status LED", false)
hw_switch_add("LED switch", 3, function(position)
if position == 0 then
timer_stop(blink_timer)
hw_output_set(status_led, false)
elseif position == 1 then
timer_stop(blink_timer)
hw_output_set(status_led, true)
elseif position == 2 then
if not timer_running(blink_timer) then
blink_timer = timer_start(nil, 1000, function(count)
hw_output_set(status_led, count%2 == 0)
end)
end
end
end)
Re: Blinking LED
Thanks guys
I used Ralph's code , modified it a bit because i use a 3 position switch with middle position not having an input pin, but the result is a blinking led when switch is in the right position!
I used Ralph's code , modified it a bit because i use a 3 position switch with middle position not having an input pin, but the result is a blinking led when switch is in the right position!