István Cserny / Mbed 2 deprecated Lab04_reaction_time

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
cspista
Date:
Thu Nov 11 14:41:07 2021 +0000
Commit message:
Final revision

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 a64eae449008 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 11 14:41:07 2021 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+Serial pc(USBTX,USBRX); 
+DigitalOut myled(LED1);             //define LED
+DigitalIn mybutton(BUTTON1,PullUp); //define pushbutton input with pull-up
+Timer t;                            //define timer
+int x;                              //x for random number storage
+
+int main() {
+    pc.baud(115200);
+    myled = 0;                      //LED is initially off 
+    pc.printf("\r\nReaction test!\r\n");
+    pc.printf("Push the button when the LED is on!\r\n");
+    while(1) {
+        t.reset();                  //reset the timer        
+        while(!mybutton);           //wait for button release
+        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
+        myled=1;                    //LED on
+        while(mybutton);            //wait for press
+        t.stop();                   //stop the timer
+        myled=0;                    //LED off
+        wait_ms(20);                //debounce delay
+        printf("The time taken was %f seconds\r\n", t.read());
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r a64eae449008 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 11 14:41:07 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file