perturh room legacy

Dependencies:   SMARTWAV USBDevice mbed stateScript

Fork of stateScript by Mattias Karlsson

Files at this revision

API Documentation at this revision

Comitter:
alustig3
Date:
Sat May 16 23:41:46 2015 +0000
Parent:
4:34aca2142df9
Commit message:
changes

Changed in this revision

USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
behave.cpp Show annotated file Show diff for this revision Revisions of this file
behave.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
perturbRoom_legacy.lib Show annotated file Show diff for this revision Revisions of this file
soundControl.cpp Show annotated file Show diff for this revision Revisions of this file
test.lib Show diff for this revision Revisions of this file
diff -r 34aca2142df9 -r e62cd80aa22f USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Sat May 16 23:41:46 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#335f2506f422
diff -r 34aca2142df9 -r e62cd80aa22f behave.cpp
--- a/behave.cpp	Thu Sep 25 23:42:30 2014 +0000
+++ b/behave.cpp	Sat May 16 23:41:46 2015 +0000
@@ -2,8 +2,6 @@
 #include <ctype.h>
 #include <sstream> 
 
-int16_t randomSeedCounter;  //used for seeding random numbers
-
 // These external symbols are maintained by the linker to indicate the
 // location of various regions in the device's memory.  They will be used by
 // DisplayRAMBanks() to dump the size of each RAM bank to stdout.
@@ -18,7 +16,8 @@
 extern eventQueue mainQueue;
 extern digitalPort* portVector[];
 
-extern Serial pc;
+extern USBSerial pc;
+//extern Serial device; //ANDY
 extern bool resetTimer;
 extern bool clockSlave;
 extern bool changeToSlave;
@@ -132,6 +131,19 @@
     triggerDownEventPtr = NULL;
     outStateChanged = false;
 }
+digitalPort::digitalPort(DigitalOut* DOP):  //added by me
+    outPin(DOP),
+    outState(0){
+    
+    lastChangeTime = 0;
+    lastOutChangeTime = 0;
+    lastChangeInterval = 0;
+    lastDownEvent.triggered = false;
+    lastUpEvent.triggered = false;
+    triggerUpEventPtr = NULL;
+    triggerDownEventPtr = NULL;
+    outStateChanged = false;
+}
 
 void digitalPort::setTriggerUpEvent(event* eventInput) {
     if (triggerUpEventPtr != NULL) {
@@ -259,7 +271,7 @@
     isUsed = false;     
 }
 
-displayAction::displayAction(int* variable, string varNameInput, Serial* pcPtrInput):
+displayAction::displayAction(int* variable, string varNameInput, USBSerial* pcPtrInput):
     dVariable(variable),
     dText(varNameInput),
     pcPtr(pcPtrInput) {
@@ -267,14 +279,14 @@
     
 }
 
-displayAction::displayAction(string text, Serial* pcPtrInput):
+displayAction::displayAction(string text, USBSerial* pcPtrInput):
     dText(text),
     pcPtr(pcPtrInput) {   
     dVariable = NULL;
     isUsed = true;  
 }
 
-void displayAction::set(int* variable, string varNameInput, Serial* pcPtrInput) {
+void displayAction::set(int* variable, string varNameInput, USBSerial* pcPtrInput) {
     dVariable = variable;
     dText = varNameInput;
     pcPtr = pcPtrInput;
@@ -282,7 +294,7 @@
     
 }
 
-void displayAction::set(string text, Serial* pcPtrInput) {
+void displayAction::set(string text, USBSerial* pcPtrInput) {
     dText = text;
     pcPtr = pcPtrInput;   
     dVariable = NULL;
@@ -912,8 +924,7 @@
         return *intVal;    
     } else if (cmpVal != NULL){
         
-        srand(*globalTimeKeeperPtr+randomSeedCounter);
-        randomSeedCounter++; //for seeding the next rand call, just in case it happens before the clock advances     
+        srand(*globalTimeKeeperPtr);     
         *cmpVal = (rand() % (randHigh+1)); //this is how we assign a random number to variable
         return *cmpVal;
         
@@ -1681,72 +1692,7 @@
     delete actionPtr;
  }
  
- blockBuffer::blockBuffer() {
-    bufferWritePos = 0;
-    bufferWritePos = 0;
-    _linesAvailable = 0;
-    
- }
-
- bool blockBuffer::addLine(char *input, int numChars) {
-    
-    if (bufferWritePos+numChars >= INPUTCHARBUFFERSIZE) {
-        return false;
-    }
-    for(int i=0;i<numChars;i++) {
-       charBuffer[bufferWritePos] = input[i];
-       bufferWritePos++;            
-    }
-    _linesAvailable++;
-    return true;      
- }
- 
- string blockBuffer::getNextLine() {
- 
-    string outputLine;
-    int endOfLinePos = bufferReadPos;
-    bool endOfLineFound = false;
-    if (_linesAvailable > 0) {
-        //Find the end of the next line
-        while (endOfLinePos < INPUTCHARBUFFERSIZE) {
-            if (charBuffer[endOfLinePos] == '\0') {               
-                endOfLineFound = true;
-                break;
-            }
-            endOfLinePos++;
-        }
-        
-        //If the end was found, copy to output string
-        if (endOfLineFound) {           
-            outputLine.append(charBuffer+bufferReadPos,endOfLinePos-bufferReadPos);
-            bufferReadPos = endOfLinePos+1; 
-            _linesAvailable--;            
-        }
-    }
-    if (_linesAvailable == 0) {
-        //we have read out all of the lines, so reset the buffer for the next block.
-        resetBuffer();
-    }
-    return outputLine;
-        
- }
- 
- int16_t blockBuffer::linesAvailable() {
-     return _linesAvailable;
- }
- 
- void blockBuffer::resetBuffer() {
-    _linesAvailable = 0;
-    bufferReadPos = 0;
-    bufferWritePos = 0;    
- }
- 
- bool blockBuffer::empty() {
-     return (_linesAvailable == 0);
- }
-     
- 
- scriptStream::scriptStream(Serial* serialInput, digitalPort** portVectorInput, int numPortsInput, eventQueue* queueInput):
+ scriptStream::scriptStream(USBSerial* serialInput, digitalPort** portVectorInput, int numPortsInput, eventQueue* queueInput):
     portVector(portVectorInput),
     numPorts(numPortsInput),
     pcPtr(serialInput),
@@ -1756,9 +1702,42 @@
     currentTriggerPort = -1;
     currentTriggerDir = 1;
     currentFunction = -1;
+     
+    lineError = false;
+    blockDepth = 0;
+    ifBlockInit = false;
+    whileBlockInit = false;
+    elseFlag = false;
+    currentDelay = 0;
     
-    randomSeedCounter = 0;  //used for seeding random numbers
+ }
+ 
+ void scriptStream::addLineToCurrentBlock(char* lineInput) {
      
+    bool compile = false;
+    bool keep = false;
+    for (int i = 0; i < 128; i++) {
+        if (lineInput[i] == ';') {
+            compile = true;
+        } else if (lineInput[i] == ' ') {
+            continue;
+        } else if (lineInput[i] == '\0') {
+            break;
+        } else {
+            keep = true;
+            compile = false;
+        }
+    }
+    if (keep) currentBlock.insert(currentBlock.begin(),string(lineInput));
+    if (compile) parseBlock();
+    
+ }
+ 
+ 
+ //SCRIPT PARSING - all script commands are defined here.
+ //-------------------------------------------------------
+ void scriptStream::parseBlock() {
+          
     lineError = false;
     blockDepth = 0;
     ifBlockInit = false;
@@ -1767,72 +1746,14 @@
     thenFlag = false;
     currentDelay = 0;
     
-       
- }
- 
- 
- void scriptStream::addLineToCurrentBlock(char* lineInput) {
-     
-    bool compile = false;
-    bool keep = false;
-    int numCharInLine = 0;
-    //A line ending with ';' then carriage return initiates the compile sequence
-    //Otherwise, add the line to the buffer and compile later
-    for (int i = 0; i < 256; i++) {
-        numCharInLine++;
-        if (lineInput[i] == ';') {
-            compile = true;
-        } else if (lineInput[i] == ' ') {
-            continue;
-        } else if (lineInput[i] == '\0') {
-            break;
-        } else {
-            keep = true;            
-            compile = false;
-        }
-        
-    }
-    //if (keep) currentBlock.insert(currentBlock.begin(),string(lineInput));
-    if (keep) {
-        if (!currentBlock.addLine(lineInput,numCharInLine)) {
-            pcPtr->printf("Error: script input buffer full. The block is too long.\r\n");
-            currentBlock.resetBuffer();
-            compile = false;                                             
-        }        
-    }
-    if (compile) {   
-        parseBlock();
-    }
-    
- }
- 
- 
- //SCRIPT PARSING - all script commands are defined here.
- //-------------------------------------------------------
- void scriptStream::parseBlock() {
-          
-    
-    lineError = false;
-    blockDepth = 0;
-    ifBlockInit = false;
-    whileBlockInit = false;
-    elseFlag = false;
-    thenFlag = false;
-    currentDelay = 0;
-    
-    
     std::size_t stringInd = 0;
     
     bool wholeLineEvaluated = false;
    
     //pcPtr->printf("\r\n"); 
     while (!currentBlock.empty()) {
-        
-             
         wholeLineEvaluated = false;
-        //tmpLine = currentBlock.back();
-        tmpLine = currentBlock.getNextLine();
-                      
+        tmpLine = currentBlock.back();
         lineError = false;
         //remove tabs
         std::size_t found = tmpLine.find_first_of(9); //tab
@@ -1888,7 +1809,6 @@
                        tmpEventPtrArray.pop_back(); //recursively remove the pointers to all else blocks
                     }
                     tmpEventPtrArray.pop_back(); //remove the pointer to the finished block
-                    
                 } else {
                     pcPtr->printf("Error: End statement without block\r\n");
                     lineError = true;
@@ -1940,12 +1860,11 @@
                         soundControl S;
                         S.setReset();
                         S.execute();
-                    } else if (isText) {
-                                             
+                    } else if (isText) {                                             
                         if (pos2-pos1-2 <= 20) {
-                            
                             soundControl S;
                             S.setFile(tmpLine.substr(pos1+1,pos2-pos1-2));
+                            S.setPlayback(true);//ANDY
                             S.execute();
                         } else {
                             pcPtr->printf("Error: sound file names must be 20 characters or less.\r\n");
@@ -2454,7 +2373,14 @@
             //              ...
             //          end
                                 
-            } else if (tokens[i].compare("do") == 0) { //the start of a block
+          }else if(tokens[i].compare("kaboom") == 0){//MAX ANDY
+            mbed_reset();            
+          }
+            
+            
+            
+            
+             else if (tokens[i].compare("do") == 0) { //the start of a block
                                       
                      if (!ifBlockInit && !whileBlockInit) {
                          
@@ -2980,7 +2906,17 @@
                         }                                        
                     }
                 }
-            } else {
+            } 
+            //ANDY
+//            else if (tokens[i].find("opto(") != std::string::npos) {
+//                wholeLineEvaluated = true;
+//                int pos1 = tmpLine.find("opto(")+5;
+//                int pos2 = tmpLine.find_first_of(")",pos1);
+//                string dispVar = tmpLine.substr(pos1,pos2-pos1);
+//                device.printf(dispVar.c_str());
+//            }
+                
+            else {
                 //if there was no match to any of the above, an error is given
                 pcPtr->printf("Error: statement not understood.\r\n");
                 lineError = true;
@@ -3002,13 +2938,8 @@
                 tokens.erase(tokens.begin());
             }
             pcPtr->printf("\r\n"); 
-            /*
             while (!currentBlock.empty()) {
                 currentBlock.pop_back();
-            }*/
-            currentBlock.resetBuffer();
-            while (!tokens.empty()) {
-                tokens.pop_back();
             }
             delete tmpEvent;
         } else {
@@ -3016,25 +2947,18 @@
             while (!tokens.empty()) {
                 tokens.pop_back();
             }
-            //currentBlock.pop_back();
-            
+            currentBlock.pop_back();
         }
 
     }
     
     //make sure that all blocks have a matching end statement
-    
-    
     if ((!lineError)&&(blockDepth > 0)) {
         pcPtr->printf("Error: Missing 1 or more end statements\r\n");
         lineError = true;
-        currentBlock.resetBuffer();            
-    }
-        
-    if ((!lineError)&&(blockDepth == 0)) {
-        textDisplay.send("~~~\r\n");
-    }
-    
+    }    
+    //pcPtr->printf("~~~\r\n"); //signals that the code was compiled
+    textDisplay.send("~~~\r\n");
     //displayMemoryLeft();
     //DisplayRAMBanks();
         
@@ -3239,7 +3163,7 @@
                         tmpOp->set(tmpVar, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()));
                     }
                     tmpAction->set(tmpOp);
-                    //pcPtr->printf("Action: change variable by constant amount\r\n");
+                    pcPtr->printf("Action: change variable by constant amount\r\n");
                 } else {
                     
                     tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
diff -r 34aca2142df9 -r e62cd80aa22f behave.h
--- a/behave.h	Thu Sep 25 23:42:30 2014 +0000
+++ b/behave.h	Sat May 16 23:41:46 2015 +0000
@@ -7,6 +7,7 @@
 #include <deque>
 #include <queue>
 #include "soundControl.h"
+#include "USBSerial.h"
 
 
 #define NUMEVENTS 50
@@ -21,10 +22,9 @@
 #define OR_CONDITION    1
 #define AND_CONDITION    2
 
-#define NUMPORTS 8
+#define NUMPORTS 5
 
-#define INPUTCHARBUFFERSIZE 3072
-
+extern "C" void mbed_reset();//MAX and ANDY
 class event; //we foreward declare this because of class interdependencies
 
 //used in the digital port class to organize digital change events
@@ -38,6 +38,7 @@
 class digitalPort {
 public:
     digitalPort(DigitalOut* DOP, DigitalIn* DIP);
+    digitalPort(DigitalOut* DOP);
     void setDigitalOut(int outVal);
     //int  getDigitalOut();
     int  getDigitalIn();
@@ -96,10 +97,10 @@
 
 public:
     displayAction();
-    displayAction(int* variable, string varNameInput, Serial* pcPtrInput);
-    displayAction(string text, Serial* pcPtrInput);
-    void set(int* variable, string varNameInput, Serial* pcPtrInput);
-    void set(string text, Serial* pcPtrInput);
+    displayAction(int* variable, string varNameInput, USBSerial* pcPtrInput);
+    displayAction(string text, USBSerial* pcPtrInput);
+    void set(int* variable, string varNameInput, USBSerial* pcPtrInput);
+    void set(string text, USBSerial* pcPtrInput);
     bool isUsed;
     void execute();
     void release();
@@ -107,7 +108,7 @@
 private:
     int* dVariable;
     string dText;
-    Serial* pcPtr;
+    USBSerial* pcPtr;
 };
 
 //intOpertaion is an action that does addition or subtraction of integers and returns/stores the result
@@ -386,30 +387,11 @@
     action* actionPtr;
 };
 
-class blockBuffer {
-    
-public:
-    blockBuffer();
-    bool addLine(char* input, int numChars);
-    string getNextLine();
-    int16_t linesAvailable();
-    bool empty();
-    void resetBuffer();
-    
-private:
-    //__attribute((section("AHBSRAM1"),aligned)) char charBuffer[INPUTCHARBUFFERSIZE];
-    char charBuffer[INPUTCHARBUFFERSIZE];       
-    int16_t bufferWritePos;
-    int16_t bufferReadPos;
-    int16_t _linesAvailable;
-    
-};
-
 //Parser for the incoming text.  The parser is called when a line terminates with a semicolon (;).
 //Only the final line in a callback block should have a semicolon.  
 class scriptStream {
 public:
-    scriptStream(Serial* serialInput, digitalPort** portVectorInput, int numPortsInput, eventQueue* queueInput);
+    scriptStream(USBSerial* serialInput, digitalPort** portVectorInput, int numPortsInput, eventQueue* queueInput);
     void parseBlock();
     void addLineToCurrentBlock(char* lineInput); // if the line did not end with a semicolon, add it to the current block
     int* findIntVariable(string nameInput); //used to retrieve the pointer to the designated variable if it exists
@@ -423,15 +405,13 @@
     
     int getRandomParam(string expression);
     
-    
-    
 private:
 
     int currentTriggerPort;
     int currentTriggerDir;
     int currentPort;
     int currentFunction;
-        
+    
     string tmpLine; 
     vector<string> tokens;
     
@@ -448,13 +428,12 @@
     vector<intVariable*> globalVariables;
     vector<event*> tmpEventPtrArray;
     vector<functionItem*> functionArray; //any blocks declared outsite callback blocks are stored here
-    //list<string> currentBlock;
-    blockBuffer currentBlock;
+    list<string> currentBlock;
     digitalPort** portVector;
     
     
     int numPorts;
-    Serial* pcPtr;
+    USBSerial* pcPtr;
     eventQueue* queuePtr;
 
 };
diff -r 34aca2142df9 -r e62cd80aa22f main.cpp
--- a/main.cpp	Thu Sep 25 23:42:30 2014 +0000
+++ b/main.cpp	Sat May 16 23:41:46 2015 +0000
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <sstream>
 #include "SMARTWAV.h"
+#include "USBSerial.h"
 
 
 uint32_t timeKeeper; //the main clock (updated every ms) 
@@ -14,7 +15,7 @@
 
 //static char buf1[0x2000] __attribute__((section("AHBSRAM0")));
 __attribute((section("AHBSRAM0"),aligned)) outputStream textDisplay(512);
-__attribute((section("AHBSRAM0"),aligned)) char buffer[256];
+__attribute((section("AHBSRAM0"),aligned)) char buffer[128];
 
 
 __attribute((section("AHBSRAM1"),aligned)) event eventBlock[NUMEVENTS];
@@ -56,59 +57,72 @@
 //Define the digial ports
 
 //Pins for clock syncing
-InterruptIn clockResetInt(p5);
-DigitalOut clockOutSync(p6);
-DigitalOut clockOutSignal(p7);
-InterruptIn clockExternalIncrement(p8);
-
-//Camera trigger signal
-//DigitalOut camera30Hz(p27);
+//InterruptIn clockResetInt(p24);
+DigitalOut clockOutSync(p19);
+DigitalOut clockOutSignal(p29);
+InterruptIn clockExternalIncrement(p30);
 
 
 //Pins for digital ports.  Each port has 1 out and 1 in
 //DigitalOut out1(LED1); //route to LED for debugging
-DigitalOut out1(p11);
-DigitalIn in1(p12);
-InterruptIn int1(p12);
+//1A,1B
+DigitalOut out1(p5);
+DigitalIn in1(p6);
+InterruptIn int1(p6);
 __attribute((section("AHBSRAM0"),aligned)) digitalPort port1(&out1, &in1);
-
-DigitalOut out2(p13);
-DigitalIn in2(p14);
-InterruptIn int2(p14);
+//1C,1D
+DigitalOut out2(p9);
+DigitalIn in2(p10);
+InterruptIn int2(p10);
 __attribute((section("AHBSRAM0"),aligned)) digitalPort port2(&out2, &in2);
-
-
-DigitalOut out3(p15);
-DigitalIn in3(p16);
-InterruptIn int3(p16);
+//2A,2B
+DigitalOut out3(p13);
+DigitalIn in3(p14);
+InterruptIn int3(p14);
 __attribute((section("AHBSRAM0"),aligned)) digitalPort port3(&out3, &in3);
-
-DigitalOut out4(p18);
-DigitalIn in4(p17);
-InterruptIn int4(p17);
+//2C,2D
+DigitalOut out4(p17);
+DigitalIn in4(p18);
+InterruptIn int4(p18);
 __attribute((section("AHBSRAM0"),aligned)) digitalPort port4(&out4, &in4);
-
+//3A,3B
 DigitalOut out5(p21);
 DigitalIn in5(p22);
 InterruptIn int5(p22);
 __attribute((section("AHBSRAM0"),aligned)) digitalPort port5(&out5, &in5);
-
-DigitalOut out6(p23);
-DigitalIn in6(p24);
-InterruptIn int6(p24);
-__attribute((section("AHBSRAM0"),aligned)) digitalPort port6(&out6, &in6);
+////3C,3D
+//DigitalOut out6(p21);
+//DigitalIn in6(p22);
+//InterruptIn int6(p22);
+//__attribute((section("AHBSRAM0"),aligned)) digitalPort port6(&out6, &in6);
+////4A,4B
+////DigitalOut out7(p9);
+////DigitalIn in7(p10);
+////InterruptIn int7(p10);
+////__attribute((section("AHBSRAM0"),aligned)) digitalPort port7(&out7, &in7);
+////5A,5B
+//DigitalOut out7(p13);
+//DigitalIn in7(p14);
+//InterruptIn int7(p14);
+//__attribute((section("AHBSRAM0"),aligned)) digitalPort port7(&out7, &in7);
+////6A,6B
+//DigitalOut out8(p23);
+//DigitalIn in8(p24);
+//InterruptIn int8(p24);
+//__attribute((section("AHBSRAM0"),aligned)) digitalPort port8(&out8, &in8);
+////Pump1
+//DigitalOut out9(p25);
+//__attribute((section("AHBSRAM0"),aligned)) digitalPort port9(&out9);
+////Pump2
+//DigitalOut out10(p26);
+//__attribute((section("AHBSRAM0"),aligned)) digitalPort port10(&out10);
 
-DigitalOut out7(p25);
-DigitalIn in7(p26);
-InterruptIn int7(p26);
-__attribute((section("AHBSRAM0"),aligned)) digitalPort port7(&out7, &in7);
+
 
-DigitalOut out8(p29);
-DigitalIn in8(p30);
-InterruptIn int8(p30);
-__attribute((section("AHBSRAM0"),aligned)) digitalPort port8(&out8, &in8);
 //Serial communication
-Serial pc(USBTX, USBRX); // tx, rx
+//Serial pc(USBTX, USBRX); // tx, rx
+USBSerial pc;
+
 
 //Main event queue
 eventQueue mainQueue(portVector, &timeKeeper);
@@ -117,8 +131,8 @@
 scriptStream parser(&pc, portVector, NUMPORTS, &mainQueue);
 
 //The sound output uses a SmartWav device and their simple serial library
-SMARTWAV sWav(p9,p10,p19);    //(TX,RX,Reset);
-
+SMARTWAV sWav(p28,p27,p26);    //(TX,RX,Reset);
+//Serial device(p9,p10);
 //Erases the input buffer for serial input
 void eraseBuffer(char* buffer,int numToErase) {
     for (int i = 0; i < numToErase; i++) {
@@ -200,7 +214,6 @@
             currentBroadcastBit = 0;
         }
     
-                
         //Every second, we broadcast out the current time 
         if ((timeKeeper % 1000) == 0) {
             currentBroadcastTime = timeKeeper;
@@ -264,10 +277,13 @@
 void callback_port5_fall(void) { int_callback(5, 0); }
 void callback_port6_rise(void) { int_callback(6, 1); }
 void callback_port6_fall(void) { int_callback(6, 0); }
-void callback_port7_rise(void) { int_callback(7, 1); }
-void callback_port7_fall(void) { int_callback(7, 0); }
-void callback_port8_rise(void) { int_callback(8, 1); }
-void callback_port8_fall(void) { int_callback(8, 0); }
+//void callback_port7_rise(void) { int_callback(7, 1); }
+//void callback_port7_fall(void) { int_callback(7, 0); }
+//void callback_port8_rise(void) { int_callback(8, 1); }
+//void callback_port8_fall(void) { int_callback(8, 0); }
+//void callback_port9_rise(void) { int_callback(9, 1); }
+//void callback_port9_fall(void) { int_callback(9, 0); }
+
 
 //This function is attached to an interrupt pin for external clock reset
 void callback_clockReset(void) {
@@ -281,11 +297,12 @@
 
 int main() {
     timeKeeper = 0; //set main clock to 0;
-    sWav.reset(); 
-    pc.baud(115200);
+//    sWav.reset(); 
+    //pc.baud(115200);
+    //device.baud(4800);
     //pc.baud(9600);
    
-    for (int i = 0; i < 9; i++) {
+    for (int i = 0; i <NUMPORTS+1; i++) {
         portVector[i] = NULL;
     }
     //We keep portVector 1-based to eliminate confusion
@@ -294,9 +311,12 @@
     portVector[3] = &port3;
     portVector[4] = &port4;
     portVector[5] = &port5;
-    portVector[6] = &port6;
-    portVector[7] = &port7;
-    portVector[8] = &port8;
+//    portVector[6] = &port6;
+//    portVector[7] = &port7;
+//    portVector[8] = &port8;
+//    portVector[9] = &port9;
+//    portVector[10] = &port10;
+    //portVector[11] = &port11;  
    
     //Callback to update the main clock 
     //timeTick1.attach_us(&incrementTime, 100);
@@ -315,15 +335,17 @@
     int4.fall(&callback_port4_fall);
     int5.rise(&callback_port5_rise);
     int5.fall(&callback_port5_fall);
-    int6.rise(&callback_port6_rise);
-    int6.fall(&callback_port6_fall);
-    int7.rise(&callback_port7_rise);
-    int7.fall(&callback_port7_fall);
-    int8.rise(&callback_port8_rise);
-    int8.fall(&callback_port8_fall);
+//    int6.rise(&callback_port6_rise);
+//    int6.fall(&callback_port6_fall);
+//    int7.rise(&callback_port7_rise);
+//    int7.fall(&callback_port7_fall);
+//    int8.rise(&callback_port8_rise);
+//    int8.fall(&callback_port8_fall);
+//   int9.rise(&callback_port9_rise);
+//   int9.fall(&callback_port9_fall);
     
-    clockResetInt.rise(&callback_clockReset);
-    clockResetInt.mode(PullDown);
+    //clockResetInt.rise(&callback_clockReset);
+    //clockResetInt.mode(PullDown);
     
     clockExternalIncrement.mode(PullDown);
       
@@ -333,21 +355,23 @@
     in3.mode(PullDown);
     in4.mode(PullDown);
     in5.mode(PullDown);
-    in6.mode(PullDown);
-    in7.mode(PullDown);
-    in8.mode(PullDown);
+//    in6.mode(PullDown);
+//    in7.mode(PullDown);
+//    in8.mode(PullDown);
+//    in9.mode(PullDown);
      
     //Set up input buffer for the serial port
     //char buffer[128];
     int bufferPos = 0;
-    eraseBuffer(buffer,256);
+    eraseBuffer(buffer,128);
     
     ostringstream timeConvert;   // stream used for the conversion
     ostringstream stateConvert; 
     char junkChar;
     int tmpChar;
     
-    while (pc.readable()) {
+    //while (pc.readable()) {
+    while (pc.available()) {
         junkChar = pc.getc();
     }   
          
@@ -363,14 +387,14 @@
             if ((tmpChar == 13) || (tmpChar == 10)) { //carrriage return
                 parser.addLineToCurrentBlock(buffer);                          
                 bufferPos = 0;
-                eraseBuffer(buffer,256);             
+                eraseBuffer(buffer,128);             
             }            
             //pc.putc(tmpChar);
         } while (tmpChar != EOF);
         
         buffer[bufferPos] = 59;
         parser.addLineToCurrentBlock(buffer);
-        eraseBuffer(buffer,256);  
+        eraseBuffer(buffer,128);  
         fclose(fp);
     } else {
         pc.printf("No startup script found.\r\n"); 
@@ -381,8 +405,13 @@
        //check the main event queue to see if anything needs to be done
        mainQueue.check();
        
+       //https://developer.mbed.org/handbook/Serial
+        //if(device.readable()) {
+//            pc.putc(device.getc());
+//        }
        //check if anything has been written to the serial input
-       if (pc.readable()) {
+       //if (pc.readable()) {
+       if (pc.available()) {
                 
             buffer[bufferPos] = pc.getc();
             bufferPos++;
diff -r 34aca2142df9 -r e62cd80aa22f perturbRoom_legacy.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/perturbRoom_legacy.lib	Sat May 16 23:41:46 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mkarlsso/code/stateScript/#34aca2142df9
diff -r 34aca2142df9 -r e62cd80aa22f soundControl.cpp
--- a/soundControl.cpp	Thu Sep 25 23:42:30 2014 +0000
+++ b/soundControl.cpp	Sat May 16 23:41:46 2015 +0000
@@ -60,11 +60,9 @@
         
         if (fileNameExists) {
             //sWav.playTracks();
-            sWav.stopTrack(); 
-            sWav.playTrackName(fileName);
-            
-                   
-            
+            sWav.stopTrack();
+            wait_ms(30);//ANDY
+            sWav.playTrackName(fileName);                
         }
     }
 }
diff -r 34aca2142df9 -r e62cd80aa22f test.lib
--- a/test.lib	Thu Sep 25 23:42:30 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://mbed.org/users/simon/code/HelloWorld/#03c191369089