Blinking LED sequence

hi,

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

Hello.

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.

- Grant

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.

To create a delay, you could use the “delay” command. This command is described in the “Command Reference” section of the Maestro user’s guide.

For the flickering effect, you could create a loop that turns an LED on and off with delays after each command.

- Grant

Would I do this as sub routines? I’m happy to play about with the code but could do with a head start

Please go ahead and try to modify the code. If you get stuck, you could post your code to the forum, and we might be able to give you some pointers.

- Grant

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

- Grant

ok great, will try that out asap.

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.

thanks for all the help so far :slight_smile:

that script works perfect! thanks for that buddy! :slight_smile: :slight_smile: :slight_smile:

still want more power going to the LED’s though lol

What current limiting resistor are you using for the LEDs?

- Grant

They each have a built in resistor. Not entirely sure :confused:

I was thinking of changing it to EL tape, but also not sure about how to get extra power to it

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.

- Grant