Albertas Galin
/
Reaction_timer
Human(oid) reaction time measurement Basic buttons,leds,timer,wait usage examples
main.cpp
- Committer:
- albertas
- Date:
- 2015-04-30
- Revision:
- 0:436ae35cdd94
File content as of revision 0:436ae35cdd94:
/* Reaction time measurement Result output to terminal your result should be about 0.220+-0.060s best result https://www.youtube.com/watch?v=XsU5AMxvlKg (youtube) */ #include "mbed.h" DigitalOut myled(LED1); //define LED DigitalIn mybutton(USER_BUTTON); //define BUTTON Timer t; //define timer int x; //x for random number storage int main() { printf("Reaction test!\n"); printf("Push the button when the LED is on!\n"); while(1) { while(1) { x=rand()%2000; //generate random number 0-2000 wait_ms(1000+x); //wait random time between 1 and 3 seconds t.start(); //start the timer if(mybutton == 0)break; //to early for push or cheating myled=1; //LED on while(1) { //wait for push if (mybutton == 0)break; } t.stop(); //stop the timer myled=0; //LED off printf("The time taken was %f seconds\n", t.read()); t.reset(); //reset the timer wait(0.5); //debounce the BUTTON } printf("Cheeting!!!\n"); wait(0.5);//debounce the BUTTON } }