AWOL:
Please post your code.
Here is all my code:
#include <Tone.h>
#define Password_Length 4 // Give enough room x characters + 1 NULL char
char Data[Password_Length]; // 6 is the number of chars it can hold + null
char Master[Password_Length] = "222"; //debugging password
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
//char strcmp;
// using Tone library
Tone freq1;
Tone freq2;
// create variable and string array for dtmf_freq1 and dtmf_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 };
//map the bits to a pin 0-7, + 1 ready bit
int dr = 12; //dr goes high when data ready
int d0 = 11; // 0 bit, bit 1
int d1 = 10; // 1 bit, bit 2
int d2 = 9; // 2 bit, bit 3
int d3 = 8; // 3 bit, bit 4
int a1 = 6;
int a2 = 7;
int buffer = 0;
char result;
//char reread;
String stringone; //use this to hold the current array
//LED Pin
int ledPin = 13;
//sets data_ready flag to 0
//create data array and sent all to 0
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("Super Secret Silo- Activation");
//intialize pins for Module
pinMode(d0, INPUT);
pinMode(d1, INPUT);
pinMode(d2, INPUT);
pinMode(d3, INPUT);
pinMode(dr, INPUT);
freq1.begin(a1);
freq2.begin(a2);
//setup LED pin
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
//**********************-BEGIN LOOP-**********************
void loop() {
static unsigned long int time, task, tx_time;
char tmp;
time = millis();
//data_ready_status is pin 6, HIGH or LOW, goes to high when ready
data_ready_status = digitalRead(dr);
// //*** UNCOMMENT THIS OUT IF YOU WANT THE AUTO LOOP OF RANDOM NUMBER*******
// // OTHERWISE USE AN EXTERANL DTMF DEVICE TO INJECT SIGNAL TO MODULE
// Serial.print("Task 1 ");
// Serial.println(task);
// if (time - task > 1000) // send random char every 500ms
// {
//
//
// task = time;
// //If something was already being read, time it out. Capture not complete
// if (tx_in_progress) {
// Serial.println("Rx Timeout");
// }
//
// //declare randNumber and set it to random 1-9
// char randNumber = random(9);
//
//
// Serial.print("\n\rTransmitt: ");
// Serial.println(randNumber, DEC);
//
// //Pass randNumber through playDTMF function
// playDTMF(randNumber, 500);
// //set bit to 1 to signify valid tone received
// tx_in_progress = 1;
// }
// If module flag "hears" tone, it sets to TRUE
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 using the function below
// char array = char(tmp,BIN);
Serial.print("Recieve: ");
Serial.println(tmp, DEC); // this display works fine
Serial.println();
Serial.print("******************");
Serial.println();
//STORE INTO ARRY
Data[data_count] = tmp; // store char into data array
String stringOne = Data;
Serial.println();
Serial.print("%%%%%%% ");
Serial.print("Current Array is ");
Serial.print(Data); // <<-------------THIS IS WHERE THE STRING IS EMPTY
Serial.print(" %%%%%%%%");
Serial.println();
data_count++;
if (data_count == Password_Length-1) {
Serial.println();
Serial.print("Password is ");
if (!strcmp(Data, Master)) { // equal to (strcmp(Data, Master) == 0
// Here we compare the Data array to the Master password
Serial.print(" GOOD ");
digitalWrite(ledPin, HIGH);
delay(5000);
data_count =0;
}
else
Serial.print(" BAD ");
Serial.println();
digitalWrite(ledPin, LOW);
buffer = 0;
data_count = 0;
delay (1000);
}
// This just for indexing
Serial.print("Index Counter is at: ");
Serial.print(data_count);
Serial.println();
Serial.print("******************");
Serial.println();
dr_serviced = 1; //clear received flag
tx_in_progress = 0; //clear tx in progress flag
}
}
else
dr_serviced = 0;
}
//END LOOP HERE(((((((((((((((((((((((((((((((((((((((((((((((())))))))))
// ----DTMF receive functions ----
char dtmf_digit ( void ) //assemble the bits into a digit
{
char dtmf_digit;
// dtmf digit is 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);
}
int interpret() {
// int Q1State = digitalRead(Q1);
// int Q2State = digitalRead(Q2);
// int Q3State = digitalRead(Q3);
// int Q4State = digitalRead(Q4);
if (0){result = '1' ;}
if (0){result = '2' ;}
if (0){result = '3' ;}
if (0){result = '4' ;}
if (0){result = '5' ;}
if (0){result = '6' ;}
if (0){result = '7' ;}
if (0){result = '8' ;}
if (0){result = '9' ;}
if (0){result = '0' ;}
return result;
}
void clearData()
{
while(data_count !=0)
{ // This can be used for any array size.
Data[data_count--] = 0; //clear array for new data
}
Serial.println();
Serial.print("Buffer Cleared");
Serial.println();
return;
}
Here is the output after pressing '222' on my DTMF device:
Notice the "Current Array is {blank}"
Super Secret Silo- Activation
Recieve: 2
%%%%%%% Current Array is %%%%%%%%
Index Counter is at: 1
Recieve: 2
%%%%%%% Current Array is %%%%%%%%
Index Counter is at: 2
Recieve: 2
%%%%%%% Current Array is %%%%%%%%
Password is BAD
Index Counter is at: 0