Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832_lcd mbed
main.cpp
00001 #include "mbed.h" 00002 #include "DebouncedIn.h" 00003 #include "C12832_lcd.h" 00004 00005 Ticker tick; 00006 C12832_LCD lcd; 00007 DigitalOut led1(LED1); 00008 DigitalOut led2(LED2); 00009 DigitalOut led3(LED3); 00010 DigitalOut led4(LED4); 00011 00012 DebouncedIn button(p12); 00013 00014 volatile unsigned int event=0; 00015 float initTime = 0; 00016 bool startreaction = false; 00017 float reactionTime = 0; 00018 00019 void reactionTick(); 00020 void startTime(); 00021 00022 void RandomTime() 00023 { 00024 float min = 0.8 / 6.3; 00025 float max = 6.2 / 6.3; 00026 00027 initTime = min + ((float)rand()/RAND_MAX) * (max - min) * 6.3; 00028 } 00029 00030 void startTimerStart() 00031 { 00032 RandomTime(); 00033 tick.attach(&startTime, 0.1); 00034 } 00035 00036 void reactionTimerStart() 00037 { 00038 reactionTime = 0; 00039 tick.attach(&reactionTick, 0.001); 00040 } 00041 00042 void stopTimer() 00043 { 00044 tick.detach(); 00045 } 00046 00047 void ledsEin() 00048 { 00049 led1 = 1; 00050 led2 = 1; 00051 led3 = 1; 00052 led4 = 1; 00053 } 00054 00055 void ledsAus() 00056 { 00057 led1 = 0; 00058 led2 = 0; 00059 led3 = 0; 00060 led4 = 0; 00061 } 00062 00063 void startTime() 00064 { 00065 initTime -= 0.1; 00066 00067 if(initTime <= 0) 00068 { 00069 startreaction = true; 00070 ledsAus(); 00071 stopTimer(); 00072 reactionTimerStart(); 00073 } 00074 } 00075 00076 void reactionTick() 00077 { 00078 reactionTime += 0.001; 00079 } 00080 00081 void doEvent() 00082 { 00083 switch(event) 00084 { 00085 case 0: 00086 ledsAus(); 00087 lcd.cls(); 00088 lcd.locate(0, 0); 00089 lcd.printf("Reaktionstester: "); 00090 break; 00091 case 1: 00092 ledsEin(); 00093 lcd.printf("Running: "); 00094 startTimerStart(); 00095 break; 00096 case 2: 00097 if(startreaction) 00098 { 00099 stopTimer(); 00100 lcd.locate(0, 10); 00101 lcd.printf("Zeit: %.3f s", reactionTime); 00102 } 00103 else 00104 { 00105 stopTimer(); 00106 lcd.locate(0, 10); 00107 lcd.printf("Zu frueh!!!!"); 00108 } 00109 break; 00110 case 3: 00111 event = 0; 00112 ledsAus(); 00113 lcd.cls(); 00114 lcd.locate(0, 0); 00115 lcd.printf("Reaktionstester: "); 00116 break; 00117 default: 00118 break; 00119 } 00120 } 00121 00122 int main() 00123 { 00124 doEvent(); 00125 00126 while(1) { 00127 if (button.rising()) { 00128 event++; 00129 doEvent(); 00130 } 00131 } 00132 } 00133
Generated on Thu Jul 28 2022 20:29:18 by
