Really pretty simple but I hit a road block. building a DTMF decoder using a MT8877 board.
decodes fine but i need it to decode a string of digits before it does what I want. so rigth now I send it DTMF 4 and it turns a relay on. what I need it to do is what for a string of digits so maybe something like 141 to turn on and 140 to turn off. just and example. I took a couple stabs at writing a little code to do this but got now where.
seems like I need a time varable that makes the code what for the number of digits I need.
eventually i would like to have a code which I would have to enter that would then allow me to send addition codes to turn things on and off. then after a predetermined amount of time the master code times out without activity and resets.
ideas?
//Global variables-----------------------------------------------------------------------------------------
byte DTMFread; // The DTMFread variable will be used to interpret the output of the DTMF module.
const int STQ = A0; // Attach DTMF Module STQ
const int Q4 = A4; // Attach DTMF Module Q4
const int Q3 = A3; // Attach DTMF Module Q3
const int Q2 = A2; // Attach DTMF Module Q2
const int Q1 = A1; // Attach DTMF Module Q1
int R1 = 4;
int R2 = 5;
int R3 = 6;
int R4 = 7;
unsigned long lastDTMFtime = 0;
/*=========================================================================================================
========================================================================================================== */
void setup() {
Serial.begin(57600);
pinMode(STQ, INPUT);
pinMode(Q4, INPUT);
pinMode(Q3, INPUT);
pinMode(Q2, INPUT);
pinMode(Q1, INPUT);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(R3, OUTPUT);
pinMode(R4, OUTPUT);
digitalWrite(R1, LOW);
digitalWrite(R2, LOW);
digitalWrite(R3, LOW);
digitalWrite(R4, LOW);
}
void adjust()
{
if(digitalRead(STQ)==HIGH){ //When a DTMF tone is detected, STQ will read HIGH for the duration of the tone.
DTMFread=0;
if(digitalRead(Q1)==HIGH){ //If Q1 reads HIGH, then add 1 to the DTMFread variable
DTMFread=DTMFread+1;
}
if(digitalRead(Q2)==HIGH){ //If Q2 reads HIGH, then add 2 to the DTMFread variable
DTMFread=DTMFread+2;
}
if(digitalRead(Q3)==HIGH){ //If Q3 reads HIGH, then add 4 to the DTMFread variable
DTMFread=DTMFread+4;
}
if(digitalRead(Q4)==HIGH){ //If Q4 reads HIGH, then add 8 to the DTMFread variable
DTMFread=DTMFread+8;
}
Serial.println(DTMFread);
}
{
int DTMFstring = DTMFread
unsigned long timeNow = millis();
}
}
void loop() {
adjust();
{
if (DTMFread == 4) {
digitalWrite(R4, HIGH);
}
else {
digitalWrite(R4, LOW);
}
}
}