Morse Code via iPhone LED

2019-02-28 18:08发布

问题:

I have coded an App that can convert normal Text like : "Hello my Name is XY"

into points and strokes ( ..-. ; --.- ; . ; - ; etc etc)

Now I want to Convert these points and stroke into light flashes with the lenght of 0.3 sec for points an 0.6 seconds for strokes. also there is a pause with the length of a point after each point or stroke, a double pause after each Word, and a tripple pause/break after each sentences.

The breaks are also implied into my code.

The problem is now that the light strokes aren't different enough.

Because the Idea behind it is to convert the Light flashes via an Arduino Duo and a fototransistor back to Text.

Here is the Code Passage for the Light converting Process:

- (IBAction)send:(id)sender{

// Converting Text to morsecode etc

float needTime;
NSString *string = plotter;
for (int d = 0;d < [string length]; d++) {
    NSString *punktoderstrich = [string substringWithRange:NSMakeRange(d, 1)];
    if ([punktoderstrich isEqualToString:@"."]) {
        needTime = needTime + 0.4f;
        [self performSelector:@selector(playpunkt) withObject:nil afterDelay:needTime];
    }
    if ([punktoderstrich isEqualToString:@"-"]) {
        needTime = needTime + 1.0f;
        [self performSelector:@selector(playstrich) withObject:nil afterDelay:needTime];
    }
    if ([punktoderstrich isEqualToString:@" "]) {
        needTime = needTime + 0.4f;
        [self performSelector:@selector(playpause) withObject:nil afterDelay:needTime];

    }
    if ([punktoderstrich isEqualToString:@"/"]) {
        needTime = needTime + 0.3f;
        [self performSelector:@selector(playpause) withObject:nil afterDelay:needTime];

    }
}

- (void)torchAn {
[captureDevice lockForConfiguration:nil];
[captureDevice setTorchMode:AVCaptureTorchModeOn];
[captureDevice setFlashMode:AVCaptureFlashModeOn];
[captureDevice unlockForConfiguration];
}
- (void)torchAus {
[captureDevice lockForConfiguration:nil];
[captureDevice setTorchMode:AVCaptureTorchModeOff];
[captureDevice setFlashMode:AVCaptureFlashModeOff];
[captureDevice unlockForConfiguration];
}
-(void)playstrich{
// AudioServicesPlaySystemSound (outSystemSoundID2);
[self torchAn];
//[self performSelector:@selector(torchAus) withObject:nil afterDelay:0.8f];
}

-(void)playpunkt{
//AudioServicesPlaySystemSound (outSystemSoundID1);
[self torchAn];
//[self performSelector:@selector(torchAus) withObject:nil afterDelay:0.4f];
}

- (void)playpause{
// AudioServicesPlaySystemSound (outSystemSoundID3);
[self performSelector:@selector(torchAus) /*withObject:nil afterDelay:0.4f*/];
}

Like You see I also imported sound files (short and Long) but the Main target is to give a right light signal out.

My Problems:

Short lights are mostly okay, exept the first when the LED is firstly flashing. Long light signals aren't really longer. Sometimes I get equal results when I'm recording them.

And after a Long light should light up the following short ones aren't short as normal.. hm..

After I had commented the Part with the sounds out, the whole process became more stable. I also moved the Part (turning LED OFF) from the sign it self to the breaks.

I hope somebody can give me some tipps or so :)

Greets from Germany!

P.S.: My divice is an iPhone 4s (with torch ^^)

回答1:

Like Brad said the iPhone flash needs a few ms to turn on. If you still want to use it the only possibility would be (in my eyes) to change your protocol and give the single signals more time.

This slows down your transmission but on the receiver-side you could define some confidence intervals (like plus-minus 2 seconds). Maybe a human beeing would not understand your morse code because it could be too slow (but maybe they will), a machine like the iPhone as a receiver would be perfectly able to understand it.

You have to play around with the time intervals to find the shortest ones that are working.

Greetings from GER.