Arduino Speech Code

APR9600-Arduino_Random.jpg (79107Bytes)

Based on a talking-lift-buttons project published on instructables (credits to ICstation); I have modified the schematic to the following:

- Arduino Nano controls the audio storage chip APR9600 which includes 8 messages.

- Arduino generates random 8 numbers

- each number calls one of the 8 messages.

The result, it will look like as if the Arduino is talking out of its own mind.(more realistic if we extend this systems into say 50 phrases or more which may need a different audio storage module than APR9600)

I have assembled the scketch but its not working. i can use some advice please

#define APR9600 audion chip controlled by arduino
#define uint unsigned int

int ranNum;
int ranDel;

void setup()
{
 // Seed RNG from analog port.
 randomSeed(analogRead(0));
  pinMode(A0,OUTPUT);
  pinMode(A1,OUTPUT);
  pinMode(A2,OUTPUT);
  pinMode(A4,OUTPUT);
  pinMode(A5,OUTPUT);
  pinMode(A6,OUTPUT);
  pinMode(A7,OUTPUT);
  pinMode(A3,OUTPUT);
  digitalWrite(A0,HIGH);
  digitalWrite(A1,HIGH);
  digitalWrite(A2,HIGH);
  digitalWrite(A3,HIGH);
  digitalWrite(A4,HIGH);
  digitalWrite(A5,HIGH);
  digitalWrite(A6,HIGH);
  digitalWrite(A7,HIGH);
 
 
}

void loop()
{
 //Generate random number between 8 and 10
     ranNum=random(1,9);
     // Generate random delay time
     ranDel=random(25,300);
  if(ranDel==1)
    {
      delay(10);
      if(ranDel==1)
      {
        digitalWrite(A0,LOW);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        digitalWrite(A3,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        delay(10);
      }
 
    }
   
   if(ranDel==2)
{
      delay(10);
      if(ranDel==2)

    {
     
 
        digitalWrite(A0,HIGH);
        digitalWrite(A1,LOW);
        digitalWrite(A2,HIGH);
        digitalWrite(A3,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        delay(10);
      }   
  
    }
   
   if(ranDel==3)
 {
      delay(10);
      if(ranDel==3)

      {
        digitalWrite(A0,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,LOW);
        digitalWrite(A3,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        delay(10);
    }

      }
   
   if(ranDel==4)
    {
      delay(10);
      if(ranDel==4)
      {
        digitalWrite(A0,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        digitalWrite(A3,LOW);
        digitalWrite(A4,HIGH);
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        delay(10);
      }
 
    }
   
  if(ranDel==5)
   {
     delay(10);
      if(ranDel==5)
      {
        digitalWrite(A0,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        digitalWrite(A3,HIGH);
        digitalWrite(A4,LOW);
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        delay(10);
      }
 
   }
  
  if(ranDel==6)
    {
      delay(10);
      if(ranDel==6)
      {
        digitalWrite(A0,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        digitalWrite(A3,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A5,LOW);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        delay(10);
      }
 
    }
   
   if(ranDel==7)
    {
      delay(10);
      if(ranDel==7)
      {
        digitalWrite(A0,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        digitalWrite(A3,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A5,HIGH);
        digitalWrite(A6,LOW);
        digitalWrite(A7,HIGH);
        delay(10);
      }
 
    }
   
  if(ranDel==8)
   {
     delay(10);
      if(ranDel==8)
      {
        digitalWrite(A0,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        digitalWrite(A3,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,LOW);
        delay(10);
      }
 
   }
}

 

Your Comments

Thanks Duane; useful comments i was waiting for.

now I understand where things went wrong:

- I need Arduino to call any of the 8 messages stored inside APR9600. But I do not need the random delay between one message and onther. I should fix the delay to be more than the message length…so that called messages get enough time to be played.

- you used array to reduce code size. that is great because I do not know how to use arrays.so I learn

- I will do the enhancements you gave and try to post as a code properly this time and will see what happens…

Many thanks indeed

Code problem

You are using ranDel which ranges between 25 and 300 inside IF statements that range between 1 and 10. I suspect you meant to use ranNum. The second nested IFstatement is useless. Kind of crappy code. You can make this much shorter and neater.

 

yea you are right …that

yea you are right …that RanNum is not the right thing. It is part of reckless copy and paste from the net…being incompetent to write the code, I tend to borrow from here and there bits and peices.

Code

If the code in your initial post has been modified please erase the old “Bad” and replace with the current “Good”…