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: TextLCD mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "TextLCD.h" 00004 #include <time.h> 00005 00006 TextLCD lcd(p15,p16,p17,p18,p19,p20,TextLCD::LCD16x2); 00007 Serial pc(USBTX, USBRX); //set up serial 00008 DigitalOut natAPace(LED1); //leds for pacing 00009 DigitalOut natVPace(LED2); 00010 DigitalOut aPace(LED3); 00011 DigitalOut vPace(LED4); 00012 DigitalOut alarm(p5); //pin for alarm 00013 00014 InterruptIn a_Pace(p8); 00015 InterruptIn v_Pace(p9); 00016 00017 DigitalOut a_signal(p6); //connected to pm 00018 DigitalOut v_signal(p7); //connected to pm 00019 00020 unsigned volatile int a_time = 0; 00021 unsigned volatile int v_time = 0; 00022 00023 int mode = 0; //0 = random, 1 = manual, 2 = test 00024 int changeModes = 0; 00025 00026 //constants 00027 00028 const int minwait_A = 10; //all in msec 00029 const int minwait_V = 20; 00030 const int LRI = 1000; 00031 const int VRP = 400; 00032 const int PVARP = 500; 00033 const int URI = 1000; 00034 const int AVI = 100; 00035 00036 00037 00038 void send_aSignal() { 00039 a_signal = 1; 00040 natAPace = 1; 00041 wait(1); 00042 a_signal = 0; 00043 natAPace = 0; 00044 } 00045 00046 void send_vSignal() { 00047 v_signal = 1; 00048 natVPace = 1; 00049 wait(1); 00050 v_signal = 0; 00051 natVPace = 0; 00052 } 00053 00054 void test_mode() { 00055 00056 } 00057 00058 void random_mode() { 00059 pc.printf("in Random Mode"); 00060 while(mode == 0) { //only running while in random mode 00061 00062 int aWait = rand()%2000 + minwait_A; 00063 pc.printf("a wait: %d\n", aWait); 00064 int vWait = rand()%2000 + minwait_V; 00065 pc.printf("v wait: %d\n", vWait); 00066 00067 //wait for time to go 00068 pc.printf("going into a while loop"); 00069 a_time = 0; 00070 while(a_time < aWait); 00071 pc.printf("left a while loop"); 00072 send_aSignal(); 00073 vWait += v_time; //get current timeV 00074 //wait for v_time 00075 pc.printf("going into v while loop"); 00076 v_time = 0; 00077 while(v_time < vWait) {continue;} 00078 pc.printf("left v while loop"); 00079 send_vSignal(); 00080 v_time = 0; 00081 } 00082 } 00083 00084 void switch_modes() { 00085 while(true) { 00086 if(changeModes) { 00087 pc.printf("passed if statement"); 00088 switch(mode) { 00089 case 0: //becomes random 00090 pc.printf("in random"); 00091 changeModes = 0; 00092 random_mode(); 00093 break; 00094 case 1: //becomes manual 00095 pc.printf("in manual"); 00096 changeModes = 0; 00097 //don't need to do anything 00098 break; 00099 case 2: //becomes test 00100 pc.printf("in test"); 00101 changeModes = 0; 00102 test_mode(); 00103 break; 00104 00105 } 00106 //thread switch modes delay 00107 Thread::wait(1000); 00108 } 00109 } 00110 00111 } 00112 00113 00114 void received_apace() { 00115 //TODO: DO 00116 aPace = 1; 00117 } 00118 00119 void received_vpace() { 00120 //TODO: DO 00121 vPace = 1; 00122 } 00123 00124 void heart_keyboard() { 00125 while(true) { //thread is continuously running 00126 if(pc.readable()) { 00127 char c = pc.getc(); 00128 switch(c) { 00129 case 'r': //set to random mode 00130 pc.printf("setting random mode"); 00131 mode = 0; 00132 changeModes = 1; 00133 break; 00134 case 'm': //set to manual mode 00135 pc.printf("setting manual mode"); 00136 mode = 1; 00137 changeModes = 1; 00138 break; 00139 case 't': //set to test mode 00140 pc.printf("setting test mode"); 00141 mode = 2; 00142 changeModes = 1; 00143 break; 00144 case 'a': //asignal 00145 if(mode) { //only if in manual (heart_mode == 1) 00146 pc.printf("pacing a manual"); 00147 send_aSignal(); 00148 } 00149 break; 00150 case 'v': //vsignal 00151 if(mode) { //only if in manual (heart_mode == 1) 00152 pc.printf("pacing v manual"); 00153 send_vSignal(); 00154 } 00155 break; 00156 default: //erroneous key get rid of it 00157 break; 00158 } 00159 } 00160 } 00161 } 00162 00163 void tick() { 00164 while(true) { 00165 a_time++; 00166 v_time++; 00167 Thread::wait(1); 00168 } 00169 } 00170 00171 00172 int main() { 00173 //TODO: Set up threads 00174 srand(time(NULL)); 00175 pc.printf("setting up serial"); 00176 a_Pace.rise(&received_apace); 00177 v_Pace.rise(&received_vpace); 00178 00179 Thread* keyboard = new Thread(heart_keyboard); 00180 Thread* ticker = new Thread(tick, osPriorityHigh); 00181 Thread* mode = new Thread(switch_modes); 00182 00183 }
Generated on Mon Jul 18 2022 09:12:25 by
1.7.2