here original code
(it dtmf example)
-----------------------------------------------------------------
created 2-12-2013 igor ramos
*/
the code/function want add
i want 5 readings dtmf before returns data
so want take 5 readings 1 reading (as combined number)
example if got following numbers "6,2,6,8,0" it store in variable "62680"
then print number
another way of explaining
i send dtmf tone "6" -- stores 5 variable named "tone_bank"
i send dtmf tone "2" adds 2 variable named "tone_bank" *now "62"
i send dtmf tone "6" again-- adds "6" variable "tone_bank" (that value "626")
i send dtmf tone "8" adds "8" variable named "tone_bank" (that value "6268")
i send dtmf tone "0" it adds "0" variable named "tone_bank" value "62680")
since count 5 "prints" variable
(it dtmf example)
-----------------------------------------------------------------
created 2-12-2013 igor ramos
*/
code: [select]
#include <tone.h>
tone freq1;
tone freq2;
const int dtmf_freq1[] = { 1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477 };
const int dtmf_freq2[] = { 941, 697, 697, 697, 770, 770, 770, 852, 852, 852 };
int dr = 12; //dr goes high when data ready
int d0 = 11;
int d1 = 10;
int d2 = 9;
int d3 = 8;
int a1 = 6;
int a2 = 7;
char data_ready=0, data[4] = {0,0,0,0};
char data_ready_status=0;
char dr_serviced=0;
char tx_in_progress=0;
void setup() {
serial.begin(9600);
serial.println("dossant dtmf module: loopback example");
keyboard.begin();
// initialize digital pin output.
pinmode(d0, input);
pinmode(d1, input);
pinmode(d2, input);
pinmode(d3, input);
pinmode(dr, input);
freq1.begin(a1);
freq2.begin(a2);
}
// loop routine runs on , on again forever:
void loop() {
static unsigned long int time, task, tx_time;
char tmp;
time = millis();
data_ready_status = digitalread(dr);
if (time - task > 1000) // send random char every 500ms
{
task = time;
if (tx_in_progress)
serial.println("rx timeout");
char randnumber = random(9);
serial.print("\n\rtransmitting dtmf: ");
serial.println(randnumber,dec);
playdtmf(randnumber, 500);
tx_in_progress =1;
}
if (data_ready_status)
{
if (!dr_serviced)
{
//read data pins
data[0] = digitalread(d0);
data[1] = digitalread(d1);
data[2] = digitalread(d2);
data[3] = digitalread(d3);
tmp = dtmf_digit(); //assemble dtmf digit;
serial.print("dtmf digit received: ");
serial.println(tmp,dec);
dr_serviced =1; //clear received flag
tx_in_progress =0; //clear tx in progress flag
}
}
else
dr_serviced =0;
}
// ----dtmf receive functions ----
char dtmf_digit ( void ) //assemble bits digit
{
char dtmf_digit;
// dtmf digit decoded per page 5 table 1 of chip datasheet
// http://www.zarlink.com/zarlink/mt8870d-datasheet-oct2006.pdf
dtmf_digit = 8* data[3] + 4* data[2] + 2* data[1] + data[0] ;
if (dtmf_digit==10)
dtmf_digit =0;
return dtmf_digit;
}
// ----dtmf send functions ----
void playdtmf(uint8_t number, long duration)
{
freq1.play(dtmf_freq1[number], duration);
freq2.play(dtmf_freq2[number], duration);
}
the code/function want add
i want 5 readings dtmf before returns data
so want take 5 readings 1 reading (as combined number)
example if got following numbers "6,2,6,8,0" it store in variable "62680"
then print number
another way of explaining
i send dtmf tone "6" -- stores 5 variable named "tone_bank"
i send dtmf tone "2" adds 2 variable named "tone_bank" *now "62"
i send dtmf tone "6" again-- adds "6" variable "tone_bank" (that value "626")
i send dtmf tone "8" adds "8" variable named "tone_bank" (that value "6268")
i send dtmf tone "0" it adds "0" variable named "tone_bank" value "62680")
since count 5 "prints" variable
welcome forum. please read 2 posts @ top of forum nick gammon on guidelines posting here, use of code tags make code look
if have posted without using code tags, open message , select "modify" pull down menu labelled, "more", @ lower left corner of message. highlight code selecting (it turns blue), , click on "</>" icon @ upper left hand corner. click on "save" button.
code: [select]
like this
when posting source code files. also, before posting code, use ctrl-t in ide reformat code in standard format, makes easier read.if have posted without using code tags, open message , select "modify" pull down menu labelled, "more", @ lower left corner of message. highlight code selecting (it turns blue), , click on "</>" icon @ upper left hand corner. click on "save" button.
Arduino Forum > Using Arduino > Programming Questions > Need help adding code to sample code
arduino
Comments
Post a Comment