| 1 | /* |
| 2 | * DTFM |
| 3 | * <~~Harvie 2oo8 |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | DTMF keypad frequencies (with sound clips) |
| 8 | 1209 Hz 1336 Hz 1477 Hz 1633 Hz |
| 9 | 697 Hz 1 2 3 A |
| 10 | 770 Hz 4 5 6 B |
| 11 | 852 Hz 7 8 9 C |
| 12 | 941 Hz * 0 # D |
| 13 | |
| 14 | DTMF event frequencies |
| 15 | Event Low frequency High frequency |
| 16 | Busy signal 480 Hz 620 Hz |
| 17 | Dial tone 350 Hz 440 Hz |
| 18 | Ringback tone (US) 440 Hz 480 Hz |
| 19 | */ |
| 20 | |
| 21 | #define dtfmpin 13 |
| 22 | |
| 23 | void dtfm_tone(char outpin, float low, float high) { |
| 24 | int duration = 300; |
| 25 | char pin; |
| 26 | long pos, startmillis = millis(); |
| 27 | while((pos = millis()-startmillis) <= duration) { |
| 28 | pin = false; |
| 29 | if( sin((pos*low)/1000*(2*PI)) > 0) pin = true; |
| 30 | if( sin((pos*high)/1000*(2*PI)) > 0) pin = true; |
| 31 | |
| 32 | if(pin) digitalWrite(outpin, HIGH); else digitalWrite(outpin, LOW); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | int dtfm_key(char outpin, char key) { |
| 37 | switch (key) { |
| 38 | case '1': dtfm_tone(outpin, 697, 1209); break; |
| 39 | case '2': dtfm_tone(outpin, 697, 1336); break; |
| 40 | case '3': dtfm_tone(outpin, 697, 1477); break; |
| 41 | |
| 42 | case '4': dtfm_tone(outpin, 770, 1209); break; |
| 43 | case '5': dtfm_tone(outpin, 770, 1336); break; |
| 44 | case '6': dtfm_tone(outpin, 770, 1477); break; |
| 45 | |
| 46 | case '7': dtfm_tone(outpin, 852, 1209); break; |
| 47 | case '8': dtfm_tone(outpin, 852, 1336); break; |
| 48 | case '9': dtfm_tone(outpin, 852, 1477); break; |
| 49 | |
| 50 | case '*': dtfm_tone(outpin, 941, 1209); break; |
| 51 | case '0': dtfm_tone(outpin, 941, 1336); break; |
| 52 | case '#': dtfm_tone(outpin, 941, 1477); break; |
| 53 | |
| 54 | default: return 0; |
| 55 | } |
| 56 | return 1; |
| 57 | } |
| 58 | |
| 59 | void dtfm_dial(char outpin, char *keys) { |
| 60 | for(char i=0;keys[i]!=0;i++) { dtfm_key(outpin, keys[i]); delay(100); } |
| 61 | } |
| 62 | |
| 63 | void setup() // run once, when the sketch starts |
| 64 | { |
| 65 | pinMode(dtfmpin, OUTPUT); // sets the digital pin as output |
| 66 | //dtfm_dial(dtfmpin, "739136794"); |
| 67 | dtfm_tone(dtfmpin, 1, 10); |
| 68 | } |
| 69 | |
| 70 | void loop() // run over and over again |
| 71 | { |
| 72 | delay(10000); |
| 73 | } |