Go Down

Topic: Arduino/Flash conversation (Read 726 times) previous topic - next topic

krrlijn

Hi, I think I need some help of someone who is experienced in Arduino/Flash conversation.

With my Arduino board I want to measure six different voltages. I have managed to measure these and read out the values with the serial monitor. According to these values, I would like to let Flash play a specific sound file, so eg. Voltage 1 = sound file 1, voltage 2 = sound file 2, etc.

So far, I have the following code.


//ARDUINO TEST FLASH!

// ---------------------------------------------------

char serInString[100];  // array that will hold the different bytes of the string. 100=100characters;
                       // -> you must state how long the array will be else it won't work properly

int analogInput = 3;    //variables for input pin

int value = 0;          //store value

// ---------------------------------------------------

void setup(){
 pinMode(analogInput, INPUT);   //declaration of pin modes
 beginSerial(9600);             //setup serial conversation at 9600 bauds
}
 

//---------------------------------------------------------
// read (and print back) full strings from the serial port
//----------------------------------------------------------


void readSerialString (char *strArray) {
   int i = 0;
   if(serialAvailable()) {    
      while (serialAvailable()){            
         strArray = serialRead();
         i++;
      }
   }      
}

void printSerialString(char *strArray) {
    int i=0;
    if (strArray != 0) {    
        while(strArray != 0) {
           serialWrite( strArray );
           strArray = 0;                  // optional: flush the content
           i++;          
        }
    }
}

//utility function to know whether an array is empty or not
boolean isStringEmpty(char *strArray) {
    if (strArray[0] == 0) {
        return true;
    } else {
        return false;
    }
}



//----------------------------------------------------------
/*send to flash

void sendStringToFlash (char *s) {
   while (*s) {
       printByte(*s++);
       }
       printByte(0); //notify the XMLSocket that the communication is over
}


void ArduinoTestSend(int value){
 if(value==133)         {sendStringToFlash("This is number 1!");               //these are the values I read in the
   printByte(0);  //end of communication in XML socket                           //Serial monitor (133, 216, 287, ...)
 } else if(value==216)  {sendStringToFlash("This is number 2!");
   printByte(0);  //end of communication in XML socket
 } else if(value==287)  {sendStringToFlash("This is number 3!");
   printByte(0);  //end of communication in XML socket
 } else if(value==702)  {sendStringToFlash("This is number 4!");
   printByte(0);  //end of communication in XML socket
 } else if(value==845)  {sendStringToFlash("This is number 5!");
   printByte(0);  //end of communication in XML socket
 } else if(value==912)  {sendStringToFlash("This is number 6!");
   printByte(0);  //end of communication in XML socket
 }
}
//----------------------------------------------------------


//----------------------------------------------------------

void loop(){
 value = analogRead(analogInput);    //read value on analog input
 printInteger(value);                //print out value over serial port
 
 delay(2000);                          //delay of 2 seocnds


 //try to read the serial port and create a string out of what you read
 readSerialString(serInString);
 
 // prints the sentence only if Flash actually said something
 if( isStringEmpty(serInString) == false) {
 
     //first send feedback to flash that it's sentence has been heard
     printString("Arduino heard you saying: ");
     printSerialString(serInString);
           
     //optional: separate confirmation and reply in two different serial strings
     //by passing a byte(0) that informs the XMLSocket that the comunication is over
      printByte(0);
     
     //now answer to Flash continuing the conversation, sending the appropriate reply
     ArduinoTestSend( value );  
}
}

The problem: I can see Arduino confirming that he heard Flash connecting, but he does not say anything back. Does this mean that there is something wrong in the Arduino code, or do I have to make changes to the Actionscript file? I guess I do have to make changes to the Actionscript file, but I don't understand exactly what...

I hope someone can help me! I am not an experienced programmer... so I really need some help :)


Thanks a lot!

Go Up