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 X_NUCLEO_IKS01A2
main.cpp
00001 #include "mbed.h" 00002 #include "XNucleoIKS01A2.h" // inicjacja bibliotek 00003 AnalogIn Czujnik_ABP(A0); // inicjacja czujnika 00004 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);// płytka rozszerzająca 00005 static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; ////czujniki z płytki rozszerzającej 00006 static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; 00007 //coś do dziesiątek 00008 static char *print_double(char* str, double v, int decimalDigits=2) 00009 { 00010 int i = 1; 00011 int intPart, fractPart 00012 ;int len; 00013 char *ptr;/* prepare decimal digits multiplicator */ 00014 for (;decimalDigits!=0; i*=10, decimalDigits--); 00015 /* calculate integer & fractinal parts */ 00016 intPart = (int)v; 00017 fractPart= (int)((v-(double)(int)v)*i);/* fill in integer part */ 00018 sprintf(str, "%i.", intPart);/* prepare fill in of fractional part */ 00019 len = strlen(str); 00020 ptr = &str[len];/* fill in leading fractional zeros */ 00021 for (i/=10;i>1; i/=10, ptr++) 00022 { 00023 if (fractPart >= i) 00024 { 00025 break; 00026 } 00027 *ptr = '0'; 00028 }/* fill in (rest of) fractional part */ 00029 sprintf(ptr, "%i", fractPart); 00030 return str; 00031 } 00032 int main () 00033 { 00034 uint8_t id; 00035 float cisnienie, temperatura,odczyt_analog; // Deklaracja zmiennych używanych w programie 00036 char buffer1[32], buffer2[32],buffer3[32],buffer5[32]; 00037 double Idealne_cisnienie,bary,ile,cisnieni_min,cisnienie_max,Zasieg_Czujnika; 00038 int wzorzecP,wzorzecT; 00039 odczyt_analog=Czujnik_ABP.read(); // odczytanie wartości z portu A0 00040 odczyt_analog=odczyt_analog*3300; // przeliczenie wartości na mV 00041 printf("Wartosc = %.0fmV\n",odczyt_analog); 00042 00043 hum_temp->enable(); // Uruchomienie czujnika odpowiedzialnego za pomiar temperatury 00044 press_temp->enable() ; // Uruchomienie czujnika odpowiedzialnego za pomiar ciśnienia 00045 hum_temp->get_temperature(&temperatura); //Odczytanie wartości ciśnienia 00046 press_temp->get_pressure(&cisnienie); //Odczytanie wartości temperatura 00047 printf("Manometr do kol\r\n"); 00048 hum_temp->read_id(&id);// Pobranie id czujnika temperatura z płytki rozszerzenia 00049 press_temp->read_id(&id); // Pobranie id czujnika ciśnienia z płytki rozszerzenia 00050 press_temp->get_pressure(&cisnienie); // Odczyt wartości ciśnienia z płytki rozszerzenia 00051 printf(" Cisnie atmosmeryczne: %7s hPa\r\n ",print_double(buffer1, cisnienie)); // Wyświetlenie wartości ciśnienia 00052 press_temp->get_temperature(&temperatura); // Odczytanie wartości temperatury z płytki rozszerzenia 00053 printf("Temp: %7s C\r\n ", print_double(buffer2,temperatura)); // Wyświetlenie wartości temperatury 00054 wzorzecP=230000; //Ciśnieni wzorcowe w kole 00055 wzorzecT=293; // Temeratura wzorcowa w Kelwinach 00056 Idealne_cisnienie=(((wzorzecP)*(temperatura+ 273))/(wzorzecT)); // coś liczymy wartość cisnienia pożądana w kole 00057 bary=Idealne_cisnienie/100000; // przeliczenie na bary z paskali 00058 ile=(bary-(cisnienie/1000)); // ile należy upuscić z koła 00059 printf("Ile ma byc w kole? %7s B\r\n ", print_double(buffer3,bary)); // Wartość ciśnienia jaka powinna znajdować się kole 00060 printf("Ile jest w kole? %7s B\r\n ", print_double(buffer1,cisnienie/1000)); // Wartość ciśnienia jak znaduje się w kole 00061 if ((cisnienie/1000)<bary) // początek warunku if odpowiedzialnego za określenie deczycji co należy zrobić z ciśnieniem w kole (Jeżeli ciśnieni mniejsze niż 2.5 ) 00062 { 00063 printf("Upusc %7s B\r\n ", print_double(buffer5,ile )); 00064 } 00065 else if ((cisnienie/1000)>=2.5 && (cisnienie/1000)<=2.7 ) // Jeżeli ciśnienie znaduje się w przedziale <2.5;2.7> 00066 { 00067 printf("Nic nie trzeba robić %7s B\r\n ", print_double(buffer5,ile )); 00068 00069 } 00070 else if ((cisnienie/1000) > bary ) //Jeżeli ciśnienie ma wartość powyżej 2.7 00071 { 00072 printf("dobij %7s B\r\n", print_double(buffer5,ile)); 00073 } 00074 } 00075 00076 00077
Generated on Tue Jul 12 2022 21:42:55 by
1.7.2