├── README.md └── dtmf ├── changelog.txt ├── keywords.txt ├── examples └── DTMF_test │ └── DTMF_test.ino ├── dtmf.h └── dtmf.cpp /README.md: -------------------------------------------------------------------------------- 1 | DTMF 2 | ==== 3 | 4 | DTMF Decoder and Encoder shield for Arduino -------------------------------------------------------------------------------- /dtmf/changelog.txt: -------------------------------------------------------------------------------- 1 | $Id: changelog.txt 120 2013-01-17 19:01:15Z juans455@gmail.com $ 2 | 3 | DTMF Library 4 | 5 | Version Modified By Date Comments 6 | ------- ----------- -------- -------- 7 | 0001 Jose Galvez 18/01/13 Initial coding 8 | -------------------------------------------------------------------------------- /dtmf/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For DTMF 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | DTMF KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | playDTMF KEYWORD2 16 | getDTMF KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | 22 | -------------------------------------------------------------------------------- /dtmf/examples/DTMF_test/DTMF_test.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DTMF.cpp - TEST code for DTMF library 3 | */ 4 | 5 | 6 | 7 | #include "dtmf.h" 8 | 9 | DTMF dtmf; // default set to DFRobot DTMF board pins, Speaker pins 10 | 11 | void setup() 12 | { 13 | Serial.begin(9600); 14 | } 15 | 16 | void loop() 17 | { 18 | // Play a default number with all possibilities 19 | //dtmf.playDTMF(); 20 | 21 | // Read DTMF codes one by one and print it on Serial 22 | int myDtmf; 23 | myDtmf = dtmf.getDTMF(); 24 | if(myDtmf != -1) Serial.println(myDtmf); 25 | delay(80); // to avoid getting repeated output. 26 | } 27 | -------------------------------------------------------------------------------- /dtmf/dtmf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DTMF.h - Library for flashing dtmf code. 3 | * Created by Jose Galvez , January 18, 2013. 4 | * Version 0.1 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * This class creates a handle to the MT8870 DTMF decoder. It creates the 16 | * necessary methods to to read its input from a connected sound wave into 17 | * the chip. Using DTMF DFRobot shield with a microphone connected and a speaker 18 | * 19 | * This code expects 5 dedicated pins to interface the DTMF decoder and 20 | * 2 dedicated pins for the speakers to generate DTMF through arduino. 21 | */ 22 | #ifndef dtmf_h 23 | #define dtmf_h 24 | 25 | #if defined(ARDUINO) && ARDUINO >= 100 26 | #include "Arduino.h" 27 | #else 28 | #include "WProgram.h" 29 | #endif 30 | 31 | class DTMF 32 | { 33 | public: 34 | DTMF(byte = 12, byte = 11, byte = 10, byte = 9, byte = 8, byte = 2, byte = 3); 35 | int getDTMF(); 36 | void playDTMF(); 37 | private: 38 | byte _reg; 39 | byte _Q1; 40 | byte _Q2; 41 | byte _Q3; 42 | byte _Q4; 43 | byte _StD; 44 | byte _SPK1; 45 | byte _SPK2; 46 | int *_freq1[]; 47 | int *_freq2[]; 48 | }; 49 | 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /dtmf/dtmf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DTMF.h - Library for flashing dtmf code. 3 | * Created by Jose Galvez , January 18, 2013. 4 | * Version 0.1 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * This class creates a handle to the MT8870 DTMF decoder. It creates the 16 | * necessary methods to to read its input from a connected sound wave to 17 | * the chip. Using DTMF DFRobot shield with a microphone connected and a speaker 18 | * 19 | * This code expects 5 dedicated pins to interface the DTMF decoder and 20 | * 2 dedicated pins for the speakers to generate DTMF through arduino. 21 | */ 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include "Arduino.h" 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | #include "dtmf.h" 29 | 30 | DTMF::DTMF(byte Q1, byte Q2, byte Q3, byte Q4, byte StD, byte SPK1, byte SPK2) 31 | { 32 | this->_Q1 = Q1; 33 | this->_Q2 = Q2; 34 | this->_Q3 = Q3; 35 | this->_Q4 = Q4; 36 | this->_StD = StD; 37 | this->_SPK1 = SPK1; 38 | this->_SPK2 = SPK2; 39 | 40 | pinMode(Q1, INPUT); 41 | pinMode(Q2, INPUT); 42 | pinMode(Q3, INPUT); 43 | pinMode(Q4, INPUT); 44 | pinMode(StD, INPUT); 45 | pinMode(SPK1, OUTPUT); 46 | pinMode(SPK2, OUTPUT); 47 | } 48 | 49 | /** 50 | * public DTMF::getDTMF() 51 | * 52 | * Reads the binary ports of the 8870, and calculate its value. 53 | * Set to output automatically to serial for debugging purposes 54 | */ 55 | int DTMF::getDTMF() 56 | { 57 | if (digitalRead(_StD) == HIGH) 58 | { 59 | 60 | if (digitalRead(_Q1) == HIGH) _reg = 1; 61 | else _reg = 0; 62 | 63 | if (digitalRead(_Q2) == HIGH) _reg = _reg + 2; 64 | if (digitalRead(_Q3) == HIGH) _reg = _reg + 4; 65 | if (digitalRead(_Q4) == HIGH) _reg = _reg + 8; 66 | 67 | if (_reg == 10) return 0; 68 | else if (_reg == 11) return '*'; 69 | else if (_reg == 12) return '#'; 70 | else return _reg; 71 | 72 | while(1) 73 | { 74 | if(digitalRead(_StD) == LOW) 75 | break; 76 | } 77 | } 78 | else return -1; 79 | } 80 | 81 | /** 82 | * public DTMF::playDTMF() 83 | * 84 | * Stores the frequencies for the DTMF tones and 85 | * Automatically plays them depending on the input of the function. 86 | */ 87 | void DTMF::playDTMF() 88 | { 89 | const int _freq1[] = { 90 | 1336, 1209, 1336, 1477, 91 | 1209, 1336, 1477, 1209, 92 | 1336, 1477, 1209, 1477, 93 | 1633, 1633, 1633, 1633 94 | }; 95 | const int _freq2[] = { 96 | 941, 697, 697, 697, 97 | 770, 770, 770, 852, 98 | 852, 852, 941, 941, 99 | 697, 770, 852, 941 100 | }; 101 | 102 | int phone_number[] = { 103 | 1, 2, 3, 4, 104 | 5, 6, 7, 8, 105 | 9, 0, 10, 11, 106 | 12, 13, 14, 15 107 | }; 108 | 109 | int i; 110 | for(i = 0; i < (sizeof(phone_number)/sizeof(int)); i ++) { 111 | Serial.print(phone_number[i], 10); 112 | Serial.print(' '); 113 | tone(2, _freq1[phone_number[i]], 500); 114 | tone(3, _freq2[phone_number[i]], 500); 115 | delay(550); 116 | } 117 | 118 | Serial.println(); 119 | } 120 | 121 | 122 | --------------------------------------------------------------------------------