Hi need help with code writing on DTMF Shield

HI All hope all is well i'm using a UNO R3 board and need help with this Dtmf shield cant seem to get things write here tired of pulling my hair and making brushes LOL iv added the sketch at the bottom of my message what i would like is a little hand please if there is anyone who has done this or is also trying to sort out the same thing i need 8 outputs but i need to be able to make a output trigger relays from the dtmf shield (example key press 1 on keypad triggers a output and so on but i need to be able to make a code like *1234 and 1234# to trigger a output i cant just use the standard 1 for 1 or 2 for 2 outputs ) as there are a few radios that are on the same frequency connected to my radio that the shield listens to, i want to control security gates and the flood lights only ill know what the code is but as it is now anyone can press 1 or 2 and so on on there keypad radio and cause havoc , if someone can help me ill really appreciate it i also need one output with a timer like to make a relay come on and go off after say 5 seconds but must not stay on and ill mod it to the length i need.
Here is the Sketch code for the DTMF shield that i need help with
Kind regards
Clint

Here are some details on the dtmf shield and the code

  1. As indicated in the manual, the shield uses pin 2,3,4,5,6. Thus, you can make use of pin 0,1,7,8,9,10,11,12,13,A0,A1,A2,A3,A4,A5. Since i need 8 digital outputs,i can use any of the pins from this selection

int val1, val2, val3, val4;
int ledState1, ledState2, ledState3, ledState4;
// Variables used
int dtmf;
String dial;

void setup() {
Serial.begin(9600);
dial = "";

// Arduino Outputs

pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
// MT8870DE Outputs to Arduino Inputs
pinMode(2, INPUT); // Significant bit 1, pin 11 on CM8870
pinMode(3, INPUT); // Significant bit 2, pin 12 on CM8870
pinMode(4, INPUT); // Significant bit 4, pin 13 on CM8870
pinMode(5, INPUT); // Significant bit 8, pin 14 on CM8870
pinMode(6, INPUT); // Significant STD

Serial.println("System Reset");
delay(20);

}

void loop() {
while(digitalRead(6) == HIGH) {
delay(500);

Serial.println("System Start");

dtmf = 0;
if (digitalRead(2) == HIGH) dtmf = dtmf + 1;
if (digitalRead(3) == HIGH) dtmf = dtmf + 2;
if (digitalRead(4) == HIGH) dtmf = dtmf + 4;
if (digitalRead(5) == HIGH) dtmf = dtmf + 8;

if (dtmf == 1) dial = "1";
if (dtmf == 2) dial = "2";
if (dtmf == 3) dial = "3";
if (dtmf == 4) dial = "4";
if (dtmf == 5) dial = "5";
if (dtmf == 6) dial = "6";
if (dtmf == 7) dial = "7";
if (dtmf == 8) dial = "8";
if (dtmf == 9) dial = "9";
if (dtmf == 10) dial = "0";
if (dtmf == 11) dial = "*";
if (dtmf == 12) dial = "#";

Serial.println(dial); // The digit contained in DTMF data

// Handle Digit 1
if (dial == "1") {
val1 = digitalRead(13);
if(val1==0) {
ledState1=1;}
else {
ledState1=0;
}
//Serial.println(val1);
//Serial.println(ledState1);
} // Finished handling Digit 1

// Handle Digit 2
if (dial == "2") {
val2 = digitalRead(12);
if(val2==0) {
ledState2=1;}
else {
ledState2=0;
}
//Serial.println(val1);
//Serial.println(ledState1);
} // Finished handling Digit 2

// Handle Digit 3
if (dial == "3") {
val3 = digitalRead(11);
if(val3==0) {
ledState3=1;}
else {
ledState3=0;
}
//Serial.println(val1);
//Serial.println(ledState1);
} // Finished handling Digit 3

// Handle Digit 4
if (dial == "4") {
val4 = digitalRead(10);
if(val4==0) {
ledState4=1;}
else {
ledState4=0;
}
//Serial.println(val1);
//Serial.println(ledState1);
} // Finished handling Digit 4

}
digitalWrite(13, ledState1); // sets the LED to the button's value
digitalWrite(12, ledState2); // sets the LED to the button's value
digitalWrite(11, ledState3); // sets the LED to the button's value
digitalWrite(10, ledState4); // sets the LED to the button's value

}

Try #7 below:

Where you have code like this, each digit you detect replaces the previous one:

if (dtmf == 1) dial = "1";

You need to append them to produce a string. I don't like the String class (it caused stability problems in the past, and will cause fragmentation problems for the foreseeable future) but sticking with that implementation you could append by something like this:

if (dtmf == 1) dial += "1";

You would need to change the code checking the user input to recognise multi-character strings, and you will need to decide when to clear the string and start a new command.

You could achieve the same behaviour without the String class by storing your received characters in a null-terminated char array, and using strcmp() instead of the String == operator.