user27439: I am trying to use my Arduino to record some values from a photo-resister. The idea is when a character other than g is read the LED will turn on and 512 values will be recorded. 
When I type in a character in the serial monitor whether it is g or not it just says 1 or 0 but doesn't not provide me with the values I need from the photo-resistor. My code is as follows:
int timeOut = 60000;
int pollTime = 0;
int time = 0;
unsigned long startTime = 0;
unsigned long endTime = 0;
int x = 0;
int Vs[512];
int analogPin = 0;

void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  while (!waitFor('g', 200, 60e6)) {}
  analogWrite(9, 128);
  startTime = micros();
  for (x = 0; x < 512; x = x + 1)  {
    Vs[x] = (analogRead(analogPin));
  }
  endTime = micros();
  for (int x = 0; x < 512; x = x + 1)  {
    Serial.println(Vs[x]);
  }
  Serial.println(endTime - startTime);
}

void loop() {
}

boolean waitFor(char in, int pollTime, int timeOut)  {
  boolean done = false;
  char charWait;
  time = micros();
  while (time < timeOut)  {
    if (Serial.available())  {
      charWait = Serial.read();
      done = (charWait == in);
      Serial.println(done);
    }
  }
}


user10394: Like Edgar says, what you need to do is this:
bool waitFor(char in, int pollTime, unsigned long timeOut)  
{
  while (micros() < timeOut)  
  {
    if (Serial.available())  
    {
      if (Serial.read() == in)
      {
        Serial.println("done");
        return true;
      }
    }
    delay(pollTime);
  }
  return false;
}

If it still doesn't run after that then change setup() to this:
void setup() 
{
  Serial.begin(9600);
  Serial.println("Initialising...");
  pinMode(9, OUTPUT);
  while (!waitFor('g', 200, 60e6)) {}
  Serial.println("g command received...");
  analogWrite(9, 128);
  Serial.println("About to start...");
  startTime = micros();
  for (x = 0; x < 512; x = x + 1)  {
    Vs[x] = (analogRead(analogPin));
  }
  endTime = micros();
  Serial.println("Finished...");
  for (int x = 0; x < 512; x = x + 1)  {
    Serial.println(Vs[x]);
  }
  Serial.print("The result is : ");
  Serial.println(endTime - startTime);
  Serial.println("All finished.");
}


27439: <p>I am trying to use my Arduino to record some values from a photo-resister. The idea is when a character other than g is read the LED will turn on and 512 values will be recorded. </p>

<p>When I type in a character in the serial monitor whether it is g or not it just says 1 or 0 but doesn't not provide me with the values I need from the photo-resistor. My code is as follows:</p>

<pre><code>int timeOut = 60000;
int pollTime = 0;
int time = 0;
unsigned long startTime = 0;
unsigned long endTime = 0;
int x = 0;
int Vs[512];
int analogPin = 0;

void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  while (!waitFor('g', 200, 60e6)) {}
  analogWrite(9, 128);
  startTime = micros();
  for (x = 0; x &lt; 512; x = x + 1)  {
    Vs[x] = (analogRead(analogPin));
  }
  endTime = micros();
  for (int x = 0; x &lt; 512; x = x + 1)  {
    Serial.println(Vs[x]);
  }
  Serial.println(endTime - startTime);
}

void loop() {
}

boolean waitFor(char in, int pollTime, int timeOut)  {
  boolean done = false;
  char charWait;
  time = micros();
  while (time &lt; timeOut)  {
    if (Serial.available())  {
      charWait = Serial.read();
      done = (charWait == in);
      Serial.println(done);
    }
  }
}
</code></pre>
 10394: <p>Like Edgar says, what you need to do is this:</p>

<pre><code>bool waitFor(char in, int pollTime, unsigned long timeOut)  
{
  while (micros() &lt; timeOut)  
  {
    if (Serial.available())  
    {
      if (Serial.read() == in)
      {
        Serial.println("done");
        return true;
      }
    }
    delay(pollTime);
  }
  return false;
}
</code></pre>

<p>If it still doesn't run after that then change setup() to this:</p>

<pre><code>void setup() 
{
  Serial.begin(9600);
  Serial.println("Initialising...");
  pinMode(9, OUTPUT);
  while (!waitFor('g', 200, 60e6)) {}
  Serial.println("g command received...");
  analogWrite(9, 128);
  Serial.println("About to start...");
  startTime = micros();
  for (x = 0; x &lt; 512; x = x + 1)  {
    Vs[x] = (analogRead(analogPin));
  }
  endTime = micros();
  Serial.println("Finished...");
  for (int x = 0; x &lt; 512; x = x + 1)  {
    Serial.println(Vs[x]);
  }
  Serial.print("The result is : ");
  Serial.println(endTime - startTime);
  Serial.println("All finished.");
}
</code></pre>
