Hello,
I am fairly new to Arudino programming but have a basic understanding about electronics and microprocessing. I am currently working on a "tone encoder" to use as a back up system for my county fire/ems department. I have racked my brain and have tried many different designs as how to accomplish this feat. Basically what i want it to do is this....The user inputs a 2 digit code via a keypad, presses the # key to send the code to the arduino, which in turn plays the predefined "quick call" code. It will also have a LCD screen to use as a sort of a HUD so people know what the arudino is doing. Enclosed is my current sketch. I cannot get it to accept the code and play the tone, and then reset itself to accept another code. ANY help is GREATLY appreciated.
Thank you
#include <Keypad.h>
int tonepin = 26;
int tonepin2 =24;
int i = 0;
int state = 1;
int relay = 4;
char inputArray[3];
char t00[3] = {'0','0','#'};
char t01[3] = {'0','1','#'};
etc up to char t99(deleted for space)
char Str1[] = " Please Wait ";
char Str2[] = " Sending Tones ";
char Str3[] = " Tones Sent ";
char Str4[] = " Clear to Talk ";
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {12, 11, 10}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define a0 330.5
etc to a9(deleted for space)
#define b0 330,3000
etc to b9(deleted for space)
void setup(){
Serial.begin(9600);
pinMode(tonepin,OUTPUT);
Serial.write(22);
Serial.write(12);
delay(500);
Serial.write(17);
Serial.write(128);
Serial.println(Str4);
Serial.println(" ");
Serial.write(128);
pinMode(relay, OUTPUT);
pinMode(tonepin2, OUTPUT);
}
char codearray[2]; // This is the array used to store the keys pressed, it has only for numbers
int charindex = 0; // This specifies the location in the array
void page1()
{
Serial.println(Str1);
Serial.println(Str2);
Serial.write(128);
digitalWrite(relay, HIGH);
}
void page2()
{
digitalWrite(relay, LOW);
delay(3000);
Serial.println(Str3);
Serial.println(" ");
delay(3000);
softReset();
}
void tone00()
{
page1();
tone(tonepin,a0);
noTone(tonepin);
tone(tonepin2,b0);
delay(200);
page2();
}
void tone01()
{
page1();
tone(tonepin,a0);
noTone(tonepin);
tone(tonepin2,b1);
delay(200);
page2();
}
void tone02()
{
page1();
tone(tonepin,a0);
delay(200);
tone(tonepin,b2);
delay(200);
page2();
}
etc to void tone99(deleted for space)
void softReset()
{
asm volatile (" jmp 0");
}
void loop()
{
{
while (state = 1)
{
char key = keypad.getKey();
if(key)
{
inputArray[i] = key;
i++;
if (key=='*')
{
Serial.println(" Cleared ");
Serial.write(128);
softReset();
}
if (i == 2)
{
switch(i == 2)
{
case 1:
if(inputArray[0] == t00[0] &&
inputArray[1] == t00[1] &&
inputArray[2] == t00[2]);
{
tone00();
}
i==0;
break;
case 2:
if(inputArray[0] == t01[0] &&
inputArray[1] == t01[1] &&
inputArray[2] == t01[2]);
{
tone01();
}
i==0;
break;
default:
i==0;
softReset();
break;
}
}
}
}
}
}