im looking for help with LED script to add to my already working servo script.
I currently have 2 servo’s moving at the same time at the push of a button. I want to be able to push the button, servo’s go up and LED’s go off. Push button, servo’s go down… LED’s have slight delay then flicker then come on and stay on until button is pressed to go back to the start of the sequence.
here is my script so far, as used from the example on the main page… I just want to know what to add and where to add it.
im guessing its a sub routine but not sure…
goto main_loop # Run the main loop when the script starts (see below).
# This subroutine returns 1 if the button is pressed, 0 otherwise.
# To convert the input value (0-1023) to a digital value (0 or 1) representing
# the state of the button, we make a comparison to an arbitrary threshold (500).
# This subroutine puts a logical value of 1 or a 0 on the stack, depending
# on whether the button is pressed or not.
sub button
0 get_position 500 less_than
return
# This subroutine uses the BUTTON subroutine above to wait for a button press,
# including a small delay to eliminate noise or bounces on the input.
sub wait_for_button_press
wait_for_button_open_10ms
wait_for_button_closed_10ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_10ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
repeat
# Wait for the button to be pressed for at least 10 ms.
sub wait_for_button_closed_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
button
if
get_ms over minus 10 greater_than
if drop return endif
else
drop get_ms
endif
repeat
# An example of how to use wait_for_button_press is shown below:
# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
4000 4000 frame
6000 6000 frame
repeat
sub frame
wait_for_button_press
2 servo
1 servo
return
Could you describe what the program does when you actually run the script? Is there something specific that you do not understand? We are happy to help you, but we will not write your code for you.
Its for an iron man helmet. The servos lift the faceplate and turn off the eyes with button press. And then press button again and closes faceplate and turns on the eye lights.
I have no clue. The only thing I have done is set channel 5 to output. And added ‘5 servo’ to the script, along with the value ‘2000 frame
6000 frame’
I don’t know how to put a delay before LEDs turn on, or the flickering effect.
I added this to the script under the main loop. the led does come on when needed, and off when needed. but I cant see where I can put the delay or ‘flicker’ sequence
main loop
4000 4000 frame
6500 led
8000 8000 frame
return
sub frame
wait for button press
1 servo
2 servo
return
sub led
5 servo
return
Assuming you are using this code with the subroutines in the code posted at the top of this thread, this sample code contains an example of a delay and blinking an LED:
main_loop:
begin
4000 4000 frame
1000 delay # 1000 milisecond delay
led # each time the led subroutine is called the led blink once
led
led
6500 5 servo # call led to stay on
8000 8000 frame
4000 5 servo
repeat
sub frame
wait_for_button_press
1 servo
2 servo
return
sub led
6500 5 servo
100 delay # added delay for 100 miliseconds
4000 5 servo
100 delay # added delay for 100 miliseconds
return
another question is, is it possible to add a separate power supply for the led to make them brighter? at the moment there is only 4 AA batteries powering the 3 servos and 6 LED’s. the 4 AA’s are fine for the servos. but if I could add a 9v in to the LED circuit loop it would be perfect.
If you need extra power, you probably want to use a MOSFET. There are many resources on wikipedia that you can use. In particular, this picture might be helpful.
I also recommend sticking to LEDs for now since EL tape is more complex and difficult to work with.