Serial.read() each character at a time

Hello.

Imagine I Serial.read something like 'HD123'

I want to be able to buffer each character at a time, so that I can use it like:

if(buffer[0] == 0){ ... }else{ ... } if(buffer[1] == 0){ ... }else{ ... } ...

Basically, I will be constantly sending a string with 5 characters and I want to analyse them sepparately.

Any ideas?

the serial port already has a little buffer (16 bytes or so)…

do u need something like this?

a ring buffer:

const uint8_t bs = 100;
uint8_t bh, bt;
char buffer[bs];
void setup() {
  bh = bt = 0;
}
void loop() {
  while (Serial.available()) {
    uint8_t nbh++;
    if (nbh == bs)
      nbh = 0;
    if (nbh == bt)
      break; // buffer full
    const int ch = Serial.read();
    if (ch < 0)
      break;
    buffer[bh] = ch;
    bh = nbh;
  }
  while (bt != bh) {
    if (!analyze(buffer[bt]))
      break;
    bt++;
    if (bt == bs)
      bt = 0;
  }
}

-arne