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 int i; 00037 char buffer1[32], buffer2[32],buffer3[32],buffer5[32]; 00038 double Idealne_cisnienie,bary,ile; 00039 int wzorzecP,wzorzecT; 00040 00041 i=0; 00042 00043 for (i=0; i<10; i++) 00044 { 00045 00046 odczyt_analog+=Czujnik_ABP.read(); // odczytanie wartości z portu A0 00047 00048 } 00049 odczyt_analog=odczyt_analog/10; 00050 odczyt_analog=(150*((odczyt_analog*3300)-500)/4500)/14.5; // przeliczenie wartości na bary 00051 00052 00053 hum_temp->enable(); // Uruchomienie czujnika odpowiedzialnego za pomiar temperatury 00054 press_temp->enable() ; // Uruchomienie czujnika odpowiedzialnego za pomiar ciśnienia 00055 hum_temp->get_temperature(&temperatura); //Odczytanie wartości ciśnienia 00056 press_temp->get_pressure(&cisnienie); //Odczytanie wartości temperatura 00057 printf("Manometr do kol\r\n"); 00058 hum_temp->read_id(&id);// Pobranie id czujnika temperatura z płytki rozszerzenia 00059 press_temp->read_id(&id); // Pobranie id czujnika ciśnienia z płytki rozszerzenia 00060 press_temp->get_pressure(&cisnienie); // Odczyt wartości ciśnienia z płytki rozszerzenia 00061 printf(" Cisnie atmosmeryczne: %7s hPa\r\n ",print_double(buffer1, cisnienie)); // Wyświetlenie wartości ciśnienia 00062 press_temp->get_temperature(&temperatura); // Odczytanie wartości temperatury z płytki rozszerzenia 00063 printf("Temp: %7s C\r\n ", print_double(buffer2,temperatura)); // Wyświetlenie wartości temperatury 00064 wzorzecP=230000; //Ciśnieni wzorcowe w kole 00065 wzorzecT=293; // Temeratura wzorcowa w Kelwinach 00066 Idealne_cisnienie=(((wzorzecP)*(temperatura+ 273))/(wzorzecT)); // coś liczymy wartość cisnienia pożądana w kole 00067 bary=Idealne_cisnienie/100000; // przeliczenie na bary z paskali 00068 ile=(bary-odczyt_analog); // ile należy upuscić z koła 00069 printf("Ile ma byc w kole? %7s B\r\n ", print_double(buffer3,bary)); // Wartość ciśnienia jaka powinna znajdować się kole 00070 00071 00072 printf("Ile jest w kole? %7s B\r\n ", print_double(buffer1,odczyt_analog)); // Wartość ciśnienia jak znaduje się w kole 00073 00074 if (odczyt_analog>(bary+0,2)) // początek warunku if odpowiedzialnego za określenie deczycji co należy zrobić z ciśnieniem w kole (Jeżeli ciśnienie ma wartość powyżej bary+0,2) 00075 { 00076 00077 printf("Upusc %7s B\r\n ", print_double(buffer5,ile )); 00078 } 00079 else if (odczyt_analog>=(bary+0,2) && odczyt_analog<=(bary-0,2)) // Jeżeli ciśnienie znaduje się w przedziale <2.5;2.7> 00080 { 00081 printf("Nic nie trzeba robić %7s B\r\n ", print_double(buffer5,ile )); 00082 00083 } 00084 else if (odczyt_analog < (bary-0,2) ) //Jeżeli ciśnienie mniejsze niż bary-0,2) 00085 { 00086 printf("dobij %7s B\r\n", print_double(buffer5,ile)); 00087 } 00088 } 00089 00090 00091
Generated on Thu Aug 4 2022 21:49:27 by
1.7.2