What's wrong?

20 Jun 2011

Hello,

any idea what's wrong in the following simple code? On my PC I can read only up-steps, no down steps. Seems the second for-loop never works.

#include "mbed.h"

Serial pc2(USBTX, USBRX); // tx, rx

int main() {
    unsigned char i=0;

    while (1) {
        for (i=0;i<=255;i++)
            printf("\nup %i",i);

        for (i=0;i<=255;i++) 
            printf("\ndown %i",255-i);
    }
}

Thanks, Dirck

20 Jun 2011

unsigned char i=0;

It's 0 to 255. So the first loop never exits because i++ never takes it above 255. Use int i = 0

20 Jun 2011

Ok, thats hard. Better go sleeping after midnight! Thanks Andy.