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.
main.cpp
00001 // Hello World! for the TextLCD 00002 00003 #include "mbed.h" 00004 #include "TextLCD.h" 00005 #include <math.h> 00006 //#include <cmath> 00007 Ticker toggle_ueff_ticker; 00008 //Ticker toggle_ieff_ticker; 00009 TextLCD lcd(p25, p26, p21, p22, p23, p24); // rs, e, d4-d7 00010 InterruptIn mybutton(p12); 00011 InterruptIn mybutton2(p13); 00012 DigitalOut myled(LED1); 00013 00014 AnalogIn inputu(p15); 00015 int vn; 00016 int inu; 00017 float v2n, v2ninter, anu, anmoy, ueff; 00018 //float v2ninter = 0; 00019 //float anu = 0; 00020 //float anmoy = 0; 00021 //float ueff; 00022 00023 AnalogIn enteri(p17); 00024 int in; 00025 int ini; 00026 float i2n, i2ninter, ani, animoy, ieff; 00027 //float i2ninter = 0; 00028 //float ani = 0; 00029 //float animoy = 0; 00030 //float ieff; 00031 00032 float pactive; 00033 00034 //AnalogIn A0(p17); 00035 //AnalogIn A1(p18); 00036 //AnalogIn A2(p19); 00037 //AnalogIn A3(p20); 00038 int a=0; 00039 int n; 00040 int n2; 00041 int cpt; 00042 float nrj = 0; 00043 float nrjh; 00044 int nrjhint; 00045 int nrjhint_1; 00046 void toggle_ueff() { 00047 00048 00049 vn = (inputu.read_u16() - 32768); 00050 v2ninter = v2n; 00051 v2n = (vn * vn); 00052 anu = (anu + ((v2ninter + v2n)/2)); 00053 00054 00055 00056 in = ((enteri.read_u16()*1) - 32768); 00057 i2ninter = i2n; 00058 i2n = (in * in); 00059 ani = (ani + ((i2ninter + i2n)/2)); 00060 00061 n++; 00062 if (n >= 5000) 00063 { 00064 anmoy = (anu/5000.0); 00065 ueff = 0.873961*((sqrt((double)anmoy)*353.5533)/32768.0); 00066 00067 anu = 0; 00068 00069 animoy = (ani/5000.0); 00070 ieff = ((sqrt((double)animoy)*5)/32768.0); 00071 ani = 0; 00072 00073 00074 pactive = ueff*ieff; 00075 n = 0; 00076 cpt++; 00077 if(cpt == 2){ 00078 myled = 0; 00079 cpt = 0; 00080 nrj = (nrj + pactive); 00081 nrjh = nrj / 3600; 00082 nrjhint_1 = nrjhint; 00083 nrjhint = nrjh; 00084 00085 if(nrjhint >= (nrjhint_1 + 1)) 00086 { 00087 myled=1; 00088 } 00089 } 00090 } 00091 00092 } 00093 00094 00095 00096 00097 00098 void pressed() 00099 { 00100 a++; 00101 if(a>=5){ 00102 a = 0; 00103 } 00104 } 00105 00106 00107 void pressed2() 00108 { 00109 a--; 00110 if(a<=0){ 00111 a = 4; 00112 } 00113 } 00114 void clear() 00115 {lcd.cls();} 00116 00117 int main() 00118 { 00119 toggle_ueff_ticker.attach(&toggle_ueff, 0.0002); 00120 //toggle_ieff_ticker.attach(&toggle_ieff, 0.0001); 00121 mybutton.fall(&pressed); 00122 //mybutton.rise(&clear); 00123 mybutton2.fall(&pressed2); 00124 //mybutton2.rise(&clear); 00125 while(1) 00126 { 00127 pactive = ueff*ieff; 00128 clear(); 00129 lcd.locate(9,1); 00130 lcd.printf("page %d",a); 00131 00132 if(a == 0){ 00133 //clear(); 00134 lcd.locate(0,0); 00135 //lcd.putc(a); 00136 lcd.printf("Ueff = %f",ueff ); 00137 00138 lcd.locate(0,1); 00139 //lcd.putc(a); 00140 lcd.printf("Ieff = %f",ieff ); 00141 // wait(0.2); 00142 00143 } 00144 00145 00146 00147 if(a == 1){ 00148 // clear(); 00149 lcd.locate(0,0); 00150 //lcd.putc(a); 00151 lcd.printf("nrjh = %d",nrjhint ); 00152 // wait(0.2); 00153 00154 } 00155 if(a == 2){ 00156 //clear(); 00157 lcd.locate(0,0); 00158 //lcd.putc(a); 00159 lcd.printf("Pactive = %f",pactive ); 00160 //wait(0.2); 00161 00162 } 00163 if(a == 3){ 00164 // clear(); 00165 lcd.locate(0,0); 00166 //lcd.putc(a); 00167 lcd.printf("anu = %f",anu ); 00168 //wait(0.2); 00169 00170 } 00171 if(a == 4){ 00172 // lcd.locate(0,0); 00173 //lcd.putc(a); 00174 //lcd.printf("ueff = %lf",ueff ); 00175 // wait(0.2); 00176 // clear(); 00177 } 00178 wait(1.0); 00179 } 00180 }
Generated on Fri Nov 24 2023 01:28:49 by
1.7.2