title: Reading in an int serially from Matlab to arduino
body: <p>I'm trying to read in an integer value between 1 and 999 on arduino, the number is sent from matlab serially. My code on arduino is:</p>
  
  <pre><code>   while (Serial.available() &lt;= 0) {
       Serial.println('A', BYTE);   // send a capital A
       delay(300);
     }
     dec = Serial.read();
     Serial.print("I recieved: ");
     Serial.println(dec);
  </code></pre>
  
  <p>My Code on matlab for sending is as follows:</p>
  
  <pre><code>numSec = 408;
  
  s1 = serial('COM3');    % define serial port
  s1.BaudRate=9600;               % define baud rate
  set(s1, 'terminator', 'LF');   
  % define the terminator for println
  fopen(s1);
  
  try                             % use try catch to ensure fclose
                                  % signal the arduino to start collection
  w=fscanf(s1,'%s');              % must define the input % d or %s, etc.
  if (w=='A')
      display(['Collecting data']);
      %fprintf(s1,'%2d\n',numSec);     % establishContact
      fwrite(s1, numSec);
  end
  
  disp(fscanf(s1,'%s'));
  </code></pre>
  
  <p>Results were:</p>
  
  <pre><code> Collecting data 
   I recieved:255
  </code></pre>
  
  <p>The number I'm trying to send is 408. Any ideas?</p>