-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTimerManager.m
More file actions
69 lines (46 loc) · 1.26 KB
/
TimerManager.m
File metadata and controls
69 lines (46 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// TimerManager.m
// LED Incapacitator
//
// Created by Robert Schriver on 1/14/12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "TimerManager.h"
@interface TimerManager ()
- (void)stopLED;
@end
@implementation TimerManager
@synthesize flashController;
@synthesize frequencyMinimum;
@synthesize frequencyMaximum;
@synthesize duration;
-(id) init
{
if (self = [super init])
{
flashController = [FlashController init];
frequencyMinimum = 1;
frequencyMaximum = 10;
duration = .5;
}
return self;
}
-(void) startTimer
{
uint random = arc4random();
int frequency = (random % (frequencyMaximum - frequencyMinimum)) + frequencyMinimum;
printf("Random %u Frequency %d\n" , random , frequency);
double frequencyInMilliseconds = 1.0 / frequency;
double durationInMilliseconds = frequencyInMilliseconds * duration;
printf("In Timer %f\n", frequencyInMilliseconds);
[self performSelector:@selector(startTimer) withObject:nil afterDelay:frequencyInMilliseconds];
printf("Starting LED\n");
[flashController toggleStrobe:TRUE];
[self performSelector:@selector(stopLED) withObject:nil afterDelay:durationInMilliseconds];
}
-(void) stopLED
{
printf("Stopping LED\n");
[flashController toggleStrobe:FALSE];
}
@end