Guilherme Ferreira
/
acender_botoes
Turn on and off RGB Led with the 5 buttons.
Diff: main.cpp
- Revision:
- 0:3a0fab19df23
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Sep 14 17:21:39 2018 +0000 @@ -0,0 +1,71 @@ +#include "mbed.h" + +DigitalIn b1(D12); +DigitalIn b2(D11); +DigitalIn b3(D10); +DigitalIn b4(D9); +DigitalIn b5(D8); +PwmOut vr(LED_RED); +PwmOut vd(LED_GREEN); +PwmOut az(LED_BLUE); + +int main() +{ + vr=1; + vd=1; + az=1; + int contb2=0,contb3=0,contb4=0; + while(1) { + int stat; + if(!b5){ + stat=1; + wait_ms(100); + }else{ + stat=0; + wait_ms(100); + } + if(stat){ + vr=1; + vd=1; + az=1; + wait_ms(100); + }else{ + if(!b1){ + vr=0; + vd=0; + az=0; + wait_ms(100); + } + if(!b2){ + vr=0; + contb2++; + wait_ms(100); + } + if(contb2==2){ + contb2=0; + vr=1; + wait_ms(100); + } + if(!b3){ + vd=0; + contb3++; + wait_ms(100); + } + if(contb3==2){ + contb3=0; + vd=1; + wait_ms(100); + } + if(!b4){ + az=0; + contb4++; + wait_ms(100); + } + if(contb4==2){ + contb4=0; + az=1; + wait_ms(100); + } + } + } +} \ No newline at end of file