enquesta
Dependencies: mbed
Revision 0:43fc14932f22, committed 2015-10-22
- Comitter:
- marcRonquillo
- Date:
- Thu Oct 22 13:32:11 2015 +0000
- Commit message:
- enquesta
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 43fc14932f22 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 22 13:32:11 2015 +0000 @@ -0,0 +1,89 @@ +#include "mbed.h" + +DigitalIn in1(p17); +DigitalIn in2(p18); + +DigitalOut out1(p21); +DigitalOut out2(p22); + +int count1; +int count2; + +int state1[2]; //state1[1] guarda l'estat actual de in1 i state1[0] l'estat anterior +int state2[2]; //state2[1] guarda l'estat actual de in2 i state2[0] l'estat anterior + +int main() { + + out1=0; + out2=0; + + state1[0]=0; + state1[1]=0; + state2[0]=0; + state2[1]=0; + + count1=0; + count2=0; + + while(1) { + + //S'actualitzen els estats de in1 i in2 + state1[0]=state1[1]; + state1[1]=in1; + + state2[0]=state2[1]; + state2[1]=in2; + + //A + if( state1[0] != state1[1] ) + { + if( (state1[0]==0) && (state1[1]==1)) //flanc pujada + { + count1++; + if(count1==3) + { + out1=0; + count1=0; + } + + else + { + out1=1; + } + + } + + if( (state1[0]==1) && (state1[1]==0)) //flanc baixada + { + out1=0; + } + } + + + //B + if( state2[0] != state2[1] ) + { + if( (state2[0]==0) && (state2[1]==1)) //flanc pujada + { + count2++; + if(count2==4) + { + out2=0; + count2=0; + } + + else + { + out2=1; + } + + } + + if( (state2[0]==1) && (state2[1]==0)) //flanc baixada + { + out2=0; + } + } + + } +}
diff -r 000000000000 -r 43fc14932f22 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 22 13:32:11 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad \ No newline at end of file