on led by button

  1. include "mbed.h"

DigitalOut led_0(D5); DigitalOut led_1(D7); DigitalOut led_2(D8); DigitalOut led_3(D9); DigitalOut led_4(D10); DigitalOut led_5(D11); DigitalOut led_6(D12); DigitalOut led_7(D13);

DigitalIn button_0(USER_BUTTON); DigitalIn button_1(D14); DigitalIn button_2(D15);

void desplay_1(){ led_0 = 1; wait(0.05); led_0 = 0; led_1 = 1; wait(0.05); led_1 = 0; led_2 = 1; wait(0.05); led_2 = 0; led_3 = 1; wait(0.05); led_3 = 0; led_4 = 1; wait(0.05); led_4 = 0; led_5 = 1; wait(0.05); led_5 = 0; led_6 = 1; wait(0.05); led_6 = 0; led_7 = 1; wait(0.05); led_7 = 0; }

void desplay_2(){ led_7 = 1; wait(0.05); led_7 = 0; led_6 = 1; wait(0.05); led_6 = 0; led_5 = 1; wait(0.05); led_5 = 0; led_4 = 1; wait(0.05); led_4 = 0; led_3 = 1; wait(0.05); led_3 = 0; led_2 = 1; wait(0.05); led_2 = 0; led_1 = 1; wait(0.05); led_1 = 0; led_0 = 1; wait(0.05); led_0 = 0; }

void desplay_3(){ led_0 = 1; led_1 = 0; led_2 = 1; led_3 = 0; led_4 = 1; led_5 = 0; led_6 = 1; led_7 = 0; wait(0.3); led_0 = 0; led_1 = 1; led_2 = 0; led_3 = 1; led_4 = 0; led_5 = 1; led_6 = 0; led_7 = 1; wait(0.3); led_0 = 0; led_1 = 0; led_2 = 0; led_3 = 0; led_4 = 0; led_5 = 0; led_6 = 0; led_7 = 0;

}

int main() { while(1){ if(button_0 == 0){ while(1){ if(button_1 == 1) break; else if(button_2 == 1) break; desplay_1(); } } else if(button_1 == 1){ while(1){ if(button_0 == 0) break; else if(button_2 == 1) break; desplay_2(); } } else if(button_2 == 1){ while(1){ if(button_0 == 0) break; else if(button_1 == 1) break; desplay_3(); } } } }

Tags

1970-01-01 tip Revision History Files