Opzet reactietester
Dependencies: mbed
Revision 0:c9b07a2f3bcb, committed 2018-04-03
- Comitter:
- lennartgroen
- Date:
- Tue Apr 03 22:33:53 2018 +0000
- Commit message:
- test
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 c9b07a2f3bcb main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 03 22:33:53 2018 +0000 @@ -0,0 +1,87 @@ +/* +Namen: Lennart Groen +Klas: EMT1PSa +Opdracht: MBED - Stoplicht +Samengewerkt met: ... +Datum: 02-04-2018 +Inspiratie uit: +*/ + +#include <mbed.h> + +DigitalOut led(D2); +DigitalIn Button(D3); +Serial pc(USBTX, USBRX); // tx, rx + +enum machinestate +{ + create_random_time, + measure_start, + reaction, + send_time +}; + +class reactiontester +{ + private: + + public: + reactiontester(); + float set_random_time(); + +}; + +int main() +{ +enum machinestate state; +reactiontester recationtester1; +Timer timer1; +Timer timer2; +timer1.start(); +float random_time = 0.0; + +while(1){ +switch(state) + { + case create_random_time: + random_time = recationtester1.set_random_time(); + break; + case measure_start: + led = 1; + timer2.start(); + break; + case reaction: + led = 0; + timer2.stop(); + state = send_time; + break; + case send_time: + float time = timer2.read(); + pc.printf("Measured Time: "); + break; + } + if (random_time <= timer1.read() && state == create_random_time){ + state = measure_start; + } + if (Button == 1 && state == measure_start){ + state = reaction; + } + +} + +} + + +reactiontester::reactiontester() +{ + +} + +float reactiontester::set_random_time() +{ + int min_value = 3; + int max_value = 10; + float random_number = rand() % (max_value+min_value); + return random_number; +} + \ No newline at end of file
diff -r 000000000000 -r c9b07a2f3bcb mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Apr 03 22:33:53 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/994bdf8177cb \ No newline at end of file