8 years, 8 months ago.

Light goes on when it should go off

I'm a bit confused about why the code is doing something different from what I expect. Instead of the led going green for 0.1 seconds before turning red for 5 seconds, it's doing the opposite. First it becomes red for 0.1 seconds and then green for 5 seconds. What did I do wrong?

  1. include "mbed.h"

DigitalOut red_led(LED_RED); DigitalOut green_led(LED_GREEN);

int main(){

while (1) { green_led = 1; red_led = 0; wait(0.1);

green_led = 0; red_led = 1; wait (5);

} }

Be the first to answer this question.