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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#define DEBUG(x) x
//#define DEBUG(x)
// units ms
#define UNLOCK_DURATION 10000
// arduino pin assignments
#define PTT 8
#define AUDIO_OUT 9
#define LED 13
#define TONE_DETECT 2
#define D1 4
#define D2 5
#define D3 6
#define D4 7
byte tone_detected = 0;
char dtmf_key[] = {
'D', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '#', 'A', 'B', 'C' };
void dtmf_isr() {
tone_detected = 1;
}
// Setup
void setup() {
pinMode(PTT, OUTPUT);
digitalWrite(PTT, HIGH);
pinMode(LED, OUTPUT);
pinMode(TONE_DETECT, INPUT);
pinMode(D1, INPUT);
pinMode(D2, INPUT);
pinMode(D3, INPUT);
pinMode(D4, INPUT);
attachInterrupt(0, dtmf_isr, RISING);
Serial.begin(9600);
Serial.print("\r\nZL4DM 439.150 Repeater Controller\r\n\r\n");
}
void loop() {
static byte dtmf;
static byte unlocked = 0;
static unsigned long relock_time = 0;
static byte password_count = 0;
static byte password_length = 3;
static byte password[] = {
0x1, 0x4, 0x7 };
// if (!tone_detected)
// return;
if (tone_detected) {
tone_detected = 0;
dtmf = PIND >> 4;
Serial.print("Tone: ");
Serial.println(dtmf_key[dtmf]);
if (!unlocked && (dtmf == password[password_count])) {
DEBUG(Serial.println(" password hit!"));
if (++password_count == password_length) {
DEBUG(Serial.println("unlocked!"));
unlocked = 1;
relock_time = millis() + UNLOCK_DURATION;
play_tone(700, 100);
return;
}
} else {
password_count = 0;
}
if(unlocked) {
play_tone(dtmf * 100 + 200, 600);
relock_time = millis() + UNLOCK_DURATION;
return;
}
}
if (unlocked && (relock_time < millis())) {
DEBUG(Serial.println(" *locked*"));
unlocked = 0;
password_count = 0;
}
}
void play_tone(int freq, int dur) {
delay(1400);
digitalWrite(LED, HIGH);
digitalWrite(PTT, LOW);
delay(300);
tone(AUDIO_OUT, freq);
delay(dur);
noTone(AUDIO_OUT);
delay(300);
digitalWrite(PTT, HIGH);
digitalWrite(LED, LOW);
tone_detected = 0;
}
|