Fire Tone Out board

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;
          }
        }
      }
    }
  }
}

firedrum: I am fairly new to Arudino programming ... ... working on a "tone encoder" to use as a back up system for my county fire/ems department.

Will lives be at risk if this gizmo fails? If so, then stop now. Life safety devices should be built by persons skilled in the art, tested extensively, and listed for the application. If you're fairly new to this endeavor, you shouldn't be building those devices. You may think that this is only a backup, but a backup device will eventually be used. If this doesn't work when it has to, you'll never again see a decent night's sleep.

We'll operate under the presumption that you're trying, as a hobbyist, to duplicate the functions of something you've seen at the fire station. The first thing I see is that you seem to be trying to eat this elephant all at once - you've amassed a huge array of code, and you're wondering why it doesn't work. I recommend breaking it into smaller pieces, and getting those pieces working first. Then, you can start combining them, and getting the combinations to work. After a while, the elephant is all gone, a bite at a time.

I'd start with verifying that you can get keystrokes into the Arduino correctly. Write code to read some keystrokes, and Serial.print() what it reads. If that comes out correct, you've verified that the hardware, wiring, and keystroke-reading code works. Then, I'd suggest assembling sequences of strokes, with error-checking, to see if those work. And, I'd try just outputting some tones, and see if that works.

Here's something that I can identify right away:  #define a0 330.5and in function tone00(),  tone(tonepin,a0);That translates to  tone(tonepin,330.5);which tells the Arduino to output a tone at 330.5 Hz for an indefinite time. But, tone() expects an unsigned int as its second argument, while you send it a float. Some quick tests tell me that the compiler truncates the float and sends an unsigned int. But, there's no duration specified, and the next statement is noTone(tonepin);which turns off the tone. You'll never hear it. I think that you intended to put a comma in the #define rather than a period, and you wanted something besides "5" to come after it.

It's also worth noting that the code is a lot more complicated than it has to be. You can reduce that, and greatly reduce the number of lines, by going to a two-dimensional array rather than 100 short arrays, and by creating one function with an argument rather than 100 functions without one.

Can you try breaking this up into smaller sections and testing them individually? Then, when you hit a snag, you can post some short code that compiles and doesn't work, and we can help you much more effectively.

Will lives be at risk if this gizmo fails? If so, then stop now. Life safety devices should be built by persons skilled in the art, tested extensively, and listed for the application. If you're fairly new to this endeavor, you shouldn't be building those devices. You may think that this is only a backup, but a backup device will eventually be used. If this doesn't work when it has to, you'll never again see a decent night's sleep.

In short, no....this is mainly a backup to the (crappy) backup that we have in place now....so to answer your question....even if it does fail....no more than if it weren't in use in the first place

#define a0 330.5,1000 This actually isn't what i have in my sketch and i don't know where the rest of it went, it WAS actually time out to 1 second...but thank you for pointing out the mistake. fixed it it in this example to how it was originally.

I'd start with verifying that you can get keystrokes into the Arduino correctly. Write code to read some keystrokes, and Serial.print() what it reads. If that comes out correct, you've verified that the hardware, wiring, and keystroke-reading code works. Then, I'd suggest assembling sequences of strokes, with error-checking, to see if those work. And, I'd try just outputting some tones, and see if that works

Yes, i have done this prior

t's also worth noting that the code is a lot more complicated than it has to be. You can reduce that, and greatly reduce the number of lines, by going to a two-dimensional array rather than 100 short arrays, and by creating one function with an argument rather than 100 functions without one.

Can you try breaking this up into smaller sections and testing them individually? Then, when you hit a snag, you can post some short code that compiles and doesn't work, and we can help you much more effectively.

this is the best i've been able to do so far :-( i've tried to make it shorter....not sure how to do the 2d array as you stated. or the argument....i know...i suck

Yes, i have done this prior

Did it work?

i've tried to make it shorter

Well, that's a consummation devoutly to be wished, with the gazillions of lines that your program must have. But, that's not what I means when I say, "you can post some short code that compiles and doesn't work." You'll get a better response if you can target your issue more precisely. When you say, "here's a whole bunch of code that doesn't work, and it's so big that I've deleted 98% of it; what's wrong?", readers see your question as a quagmire from which there's little escape, and you'll only get replies from fools like me. If you can post a short program that demonstrates an issue that you're having trouble with, you're much more likely to get an effective response from someone that can help.

not sure how to do the 2d array as you stated. or the argument

Then it's time to learn. If you can't do those things, this project will drive you absolutely nuts. Google things like, "C arrays tutorial," or "C functions tutorial." Both subjects are way too deep and broad to describe in a post. Maybe somebody will follow up and prove me wrong on that - I hope so.

Read up, run some test programs, try some stuff, and post again. Or, show us what you did in this program, and we can try to help in smaller chunks.

...i know...i suck

This is the voice of an Arduinist? Buck up, dude, and get on with it.