Quote:
Originally Posted by veterinarian2008
Hey guys!
I need some help on getting SOS flashing on the LED.
I have the strobe working but how do I get the flash to do it at a specific set of intervals?
Thank you. BTW I know what is NSTimer on the docs but my question is how do I do it for the LED.
|
Post the code that you wrote to turn on and off the torch.
You're trying to send SOS in Morse code?
That would take some design work.
I'd create an array of on/off states (NSNumbers containing booleans), and an array of durations (NSNumbers containing floats). You'd need to fill the arrays with the correct values for the dot-dash patterns to flash SOS, and include pauses between the letters.
Code:
State Duration
on short
off short (pause)
on short
off short (pause)
on short
off long (inter-letter pause)
on long
off short (pause)
on long
off short (pause)
on long
off long (inter-letter pause)
on short
off short (pause)
on short
off short (pause)
on short
off extra long (turn off torch at end, and inter-word pause for repeat.)
I'd write a method that indexed into the array of states and set the torch to that on/off state, then started a 1-time timer at the specified duration interval that called the method again.
I'd use an instance variable to keep track of my place in the array of durations.
Once I reach the end of the array, I'd ether stop, or loop back to the beginning, depending on what I wanted to do.