VoiceBox

I am using VoiceBox Shield linked below:

https://www.sparkfun.com/tutorials/285

I am writing a program with the following specifications:

It should say 40 if value 1 is received. It should say 50,if value 2 is received. It should say 60,if value 3 is received.

I am receiving the correct value, and the program enters the correct if statements, I know this from the Serial.print text.

However, when value 1 is received, it say 40, when value 2 is received it say 40 and 50, and when value 3 is received it say 40, 50, 60.

Please check part of the code below

while (m_90==1 && n_90==1 )  {  Serial.println("message = 40"); PortOne.listen(); PortOne.print(z);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}
    while (m_30==1 && n_30==1 )  {  Serial.println("message = 50"); PortOne.listen(); PortOne.print(x);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}
    while (m_60==1 && n_60==1 )  { Serial.println("message = 60");  PortOne.listen(); PortOne.print(y);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}

Please check part of the code below

Part of answer is that you need to...

You KNOW better, by now, than to post snippets.

#include <SoftwareSerial.h>
#define txPin  2
#define RES  3
#define SPK  5
#define RDY  13
boolean m_30=0;
boolean n_30 =0;
 
boolean m_60=0;
boolean n_60 =0;
boolean m_90=0;
boolean n_90 =0;

SoftwareSerial  PortOne(0, txPin);


char x[] = {20, 96, 21, 114, 22, 88, 23, 5, 186, 7, 153, 191, 128};
char y[] = {20, 96, 21, 114, 22, 88, 23, 5, 186, 129, 186, 191, 128};
char z[] = {20, 96, 21, 114, 22, 88, 23, 5, 8, 187, 129, 14, 194, 187, 191, 128};
char sounds[] = {200, 201, 202, 203, 220, 221, 222};


////////////////////////////Receiver
int i, good, k;
byte data_in;

///////////////////////////////////////
void setup()  
{
 //////// Opening three channels serials
  Serial.begin(115200);
  PortOne.begin(9600);
  //portTwo.begin(9600);
  while(!Serial){ ; }
  while(!PortOne){ ; }
  delay(500);
  //while(!portTwo){ ; }
  //delay(500);
  /////////////////////////////////////
  pinMode(txPin, OUTPUT);
  pinMode(SPK, INPUT);
  pinMode(RDY, INPUT);   //Configure the Ready pin as an input
  pinMode(RES, OUTPUT);  //Configure Reset line as an output
  digitalWrite(RES, LOW);   //All I/O pins are configured. Reset the SpeakJet module
  delay(100);
  digitalWrite(RES, HIGH);
  
  //////////////////////////////////////
  
 
  attachInterrupt(5,data_incoming,RISING);
  pinMode(18, INPUT);
 
  
}

void loop()
{ 
  //m=0;
//n=0; 
  
  //if (m==1 && n==1)
  //{
  //PortOne.listen();
   //PortOne.print(message);
  //delay(5000);
  //m=0;
  //}
 
  
}


void data_incoming(){
    

//Serial.print("m="); Serial.println(m);Serial.print("n="); Serial.println(n);
    
    for(i=0; i<100; i++){
      delayMicroseconds(20);
      good=1;
      if(digitalRead(18)==LOW){
      good=0;
      i=100;
      }
    }//for
      
    if(good==1){
    detachInterrupt(5);
    while(1){
      if(digitalRead(18)==LOW){
        delayMicroseconds(750);

        for(i=0; i<8; i++){
          if(digitalRead(18)==HIGH)
          bitWrite(data_in, i, 1);
          else
          bitWrite(data_in, i, 0);
          delayMicroseconds(1000);
        }//for
        if(data_in=='#')
        Serial.println("");
        else
        {
        Serial.print("data_in="); 
        Serial.println(char(data_in));
        if (data_in == '3') {m_30=1;m_60=0;m_90=0;Serial.print("m_30=");Serial.println(m_30);}
        if (data_in == '2') {n_30=1;n_60=0;n_90=0;Serial.print("n_30=");Serial.println(n_30);}
        if (data_in == '6') {m_60=1;m_30=0;m_90=0;Serial.print("m_60=");Serial.println(m_60);}
        if (data_in == '5') {n_60=1;n_30=0;n_90=0;Serial.print("n_60=");Serial.println(n_60);}
        if (data_in == '9') {m_90=1;m_30=0;m_60=0;Serial.print("m_90=");Serial.println(m_90);}
        if (data_in == '8') {n_90=1;n_30=0;n_60=0;Serial.print("n_90=");Serial.println(n_90);}
      }

       break;//secondtwhile
      }//low kickoff
    //Serial.println("**********************");
    //Serial.print("m_30=");Serial.println(m_30);
    //Serial.print("n_30=");Serial.println(n_30);
    //Serial.print("m_60=");Serial.println(m_60);
    //Serial.print("n_60=");Serial.println(n_60);
    //Serial.print("m_90=");Serial.println(m_90);
    //Serial.print("n_90=");Serial.println(n_90); 
   //delay(500); 
    //Serial.println("********************");
    while (m_90==1 && n_90==1 )  {  Serial.println("message = 40"); PortOne.listen(); PortOne.print(z);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}
    while (m_30==1 && n_30==1 )  {  Serial.println("message = 50"); PortOne.listen(); PortOne.print(x);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}
    while (m_60==1 && n_60==1 )  { Serial.println("message = 60");  PortOne.listen(); PortOne.print(y);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}
    
      
      ///Serial.println("message = 60");Serial.println("message = 40"); 
      
    }//second while
    
    }//good check

  attachInterrupt(5,data_incoming,RISING);

  
  
}//routine
boolean m_30=0;
boolean n_30 =0;

Boolean variables should be assigned true or false.

SoftwareSerial  PortOne(0, txPin);

Do NOT use pin 0 for SoftwareSerial! EVER!

  while(!PortOne){ ; }

Can you find ANY other code that waits for the SoftwareSerial instance to be ready? Any?

  pinMode(txPin, OUTPUT);

You told the SoftwareSerial instance that this was its pin. Why are you f**king with it?

    while (m_90==1 && n_90==1 )  {  Serial.println("message = 40"); PortOne.listen(); PortOne.print(z);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}
    while (m_30==1 && n_30==1 )  {  Serial.println("message = 50"); PortOne.listen(); PortOne.print(x);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}
    while (m_60==1 && n_60==1 )  { Serial.println("message = 60");  PortOne.listen(); PortOne.print(y);delay(2000);m_30=0;n_30=0;m_60=0;n_60=0;m_90=0;n_90=0;}

Have you got a broken enter key? Get the damned thing fixed.

You can NOT delay() in an interrupt service routine.

What the hell are you doing using a while statement when the body can execute no more than once?

NONE of those variable names means a damned thing.

Please read the code carefully, the while loop is excuted when the interrupt is disabled.

PaulS, All your comments are un-relevant to my questions. ?

I will appreciate form you to not use bad language in your replies.

Please read the code carefully, the while loop is excuted when the interrupt is disabled.

I missed the point that you were jacking around with the interrupt handlers that way. It is almost never necessary to attach or detach interrupt handlers.

PaulS, All your comments are un-relevant to my questions. ?

Really? There is a good reason to use a while loop that can ever only iterate once?