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: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 //Interface with the LCD with UART 00004 Serial LCD(p9, p10); // tx, rx 00005 //Interface with the PC with UART 00006 Serial pc(USBTX, USBRX); // tx, rx 00007 00008 DigitalOut valve(p21); //Port 6 00009 DigitalOut pump(p22); // Port 8 00010 00011 AnalogOut speed(p18); //Port 7 00012 00013 AnalogIn temperatures(p15); 00014 AnalogIn ECG(p16); //Port 17 00015 00016 // PFC, Port11, Port12, Port3 00017 //Select between temp sensors 00018 BusOut tempSel(p12, p11); 00019 BusOut templeds(LED3, LED4); 00020 00021 // read pressure sensor 00022 AnalogIn pressure(p20); //Port 15 00023 00024 //Fan control should be PWM 00025 DigitalOut fan1(p23); // Port 19 00026 DigitalOut fan2(p24); // Port 20 00027 DigitalOut fan3(p25); // Port 21 00028 00029 //valve sync from outside 00030 DigitalIn sync(p29); // Port 9 00031 00032 //Enable the PFC 00033 DigitalOut PFC_ENABLE(p14); 00034 DigitalIn PFW(p13); 00035 00036 //when the PFC module is setteled are something is wrong 00037 InterruptIn LD_ENABLE(p17); 00038 00039 //Control the main Pump 00040 DigitalOut LOAD(p26); 00041 00042 00043 DigitalOut powerLed(LED1); 00044 DigitalOut valveLed(LED2); 00045 00046 void enableFunc(){ 00047 if(LD_ENABLE) 00048 powerLed = 1; 00049 else 00050 powerLed = 0; 00051 } 00052 00053 int freq = 60; 00054 int amp = 50; 00055 int dutyCycle = 50; 00056 bool syncState = false; 00057 00058 char temp; 00059 bool start =0; 00060 bool dataReady =0; 00061 int receivedNumber; 00062 00063 00064 int main() { 00065 00066 LD_ENABLE.mode(PullUp); 00067 00068 //set hte baudrate 00069 pc.baud(9600); 00070 LCD.baud(115200); 00071 00072 // initit 00073 pump =0; 00074 powerLed = 0; 00075 valve =0; 00076 valveLed = 0; 00077 00078 wait_ms(10); 00079 //Interupt call back functions 00080 LD_ENABLE.rise(&enableFunc); 00081 LD_ENABLE.fall(&enableFunc); 00082 00083 powerLed = 1; 00084 wait(1); 00085 powerLed = 0; 00086 PFC_ENABLE = 1; 00087 00088 while(1) { 00089 /* 00090 for (int i =0; i<3; i++){ 00091 templeds = i; 00092 tempSel = i; 00093 wait_ms(1000); 00094 pc.printf("\n\r %f",temperatures.read()); 00095 }*/ 00096 00097 //check if there is meassage from LCD 00098 if(LCD.readable()) { 00099 00100 temp = LCD.getc(); 00101 00102 00103 if (temp =='A' || temp =='C' ||temp =='E' ||temp =='G' ||temp =='I') { 00104 dataReady = 0; 00105 //package is comming 00106 start = 1; 00107 receivedNumber = 0; 00108 } 00109 00110 00111 if (start) 00112 if (temp =='B' || temp =='D' ||temp =='F' ||temp =='H' ||temp =='J') { 00113 //end of package 00114 start= 0; 00115 00116 //switch was better just laziness 00117 if (temp == 'B'){ 00118 //pc.printf (" LOAD %d ",receivedNumber); 00119 if (receivedNumber){ 00120 valveLed = 1; 00121 LOAD = 1; 00122 } 00123 else { 00124 valveLed = 0; 00125 LOAD = 0; 00126 } 00127 } 00128 else if (temp == 'D') { 00129 syncState = receivedNumber; 00130 //pc.printf (" syncState %d ",syncState); 00131 } 00132 else if (temp == 'F'){ 00133 freq = receivedNumber; 00134 //pc.printf (" freq %d ",freq); 00135 } 00136 else if (temp == 'H'){ 00137 amp = receivedNumber; 00138 speed = amp /100.0; 00139 //pc.printf (" amp %d ",amp); 00140 } 00141 else if (temp == 'J'){ 00142 dutyCycle = receivedNumber; 00143 //pc.printf (" dutyCycle %d ",dutyCycle); 00144 } 00145 00146 } else { 00147 receivedNumber = temp; 00148 00149 } 00150 } 00151 00152 00153 00154 } 00155 }
Generated on Wed Aug 10 2022 18:37:09 by
1.7.2