Proyecto Parcial
Revision 0:b79d9ad8d1c3, committed 2013-10-31
- Comitter:
- DnPlas
- Date:
- Thu Oct 31 00:31:28 2013 +0000
- Commit message:
- Proyecto Parcial;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r b79d9ad8d1c3 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 31 00:31:28 2013 +0000 @@ -0,0 +1,55 @@ +//This program will execute a little game of intermitent leds +#include "mbed.h" + +BusOut leds(D13, D10, D9, D8); +AnalogIn pot(A2); +DigitalIn bttn1(D11); +DigitalIn bttn2(D12); +Serial pc(USBTX, USBRX); + +float pot_val; //The value of the potenciometer will be a float since it is get from 0 to 1 +int on = 1, counter, reps = 100; //Declaration of variables + +void chk_bttn() //Prototype Function 1. It checks the button while pressed and assigns a certain action +{ + if (on == 8 && bttn1 ==0) + { + pc.printf("Winner!\nScore: %i\n_________\n", counter); + wait (1); + } + else + if(on !=8 && bttn1 ==0) + { + pc.printf("Loser :(\nScore: %i\n_________\n", counter); + wait(1); + } + } + + void rst_game() //Prototype Function 2. This function reset the game + { + if (bttn2 ==0) + { + counter =100; + pc.printf("Welcome back to the game!\nYour initial score is %i\n", counter); + wait (1); + } +} + + +int main () +{ + while (1) + { + pot_val=pot; //Gives to the variable pot_val the value of the potenciometer + chk_bttn(); //Checks if button 1 is pressed + rst_game(); //Resets the game + leds = on; //Turns on the leds + wait ((pot_val*200+150)/1000); //Gives pauses to each led with the same value as the potenciometer + on = on <<1; + counter = 0; + if (on==16) + { + on = 1; + } + } +} \ No newline at end of file
diff -r 000000000000 -r b79d9ad8d1c3 mbed.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Thu Oct 31 00:31:28 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/#f37f3b9c9f0b