#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; }