unsigned char next[6] = {0x02,0x04,0x08,0x10,0x20,0x01};
unsigned char n = 0x01;
for (;;) {
    if (pressed) break;
    n = next[n];
}