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
- Committer:
- percu
- Date:
- 2021-01-23
- Revision:
- 0:d704d2f21671
- Child:
- 1:f92b7ebec49f
File content as of revision 0:d704d2f21671:
#include "mbed.h" #include "XNucleoIKS01A2.h" // inicjacja bibliotek AnalogIn Czujnik_ABP(A0); // inicjacja czujnika static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);// płytka rozszerzająca static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; ////czujniki z płytki rozszerzającej static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; //coś do dziesiątek static char *print_double(char* str, double v, int decimalDigits=2) { int i = 1; int intPart, fractPart ;int len; char *ptr;/* prepare decimal digits multiplicator */ for (;decimalDigits!=0; i*=10, decimalDigits--); /* calculate integer & fractinal parts */ intPart = (int)v; fractPart= (int)((v-(double)(int)v)*i);/* fill in integer part */ sprintf(str, "%i.", intPart);/* prepare fill in of fractional part */ len = strlen(str); ptr = &str[len];/* fill in leading fractional zeros */ for (i/=10;i>1; i/=10, ptr++) { if (fractPart >= i) { break; } *ptr = '0'; }/* fill in (rest of) fractional part */ sprintf(ptr, "%i", fractPart); return str; } int main () { uint8_t id; float cisnienie, temperatura,odczyt_analog; // Deklaracja zmiennych używanych w programie char buffer1[32], buffer2[32],buffer3[32],buffer5[32]; double Idealne_cisnienie,bary,ile,cisnieni_min,cisnienie_max,Zasieg_Czujnika; int wzorzecP,wzorzecT; odczyt_analog=Czujnik_ABP.read(); // odczytanie wartości z portu A0 odczyt_analog=odczyt_analog*3300; // przeliczenie wartości na mV printf("Wartosc = %.0fmV\n",odczyt_analog); hum_temp->enable(); // Uruchomienie czujnika odpowiedzialnego za pomiar temperatury press_temp->enable() ; // Uruchomienie czujnika odpowiedzialnego za pomiar ciśnienia hum_temp->get_temperature(&temperatura); //Odczytanie wartości ciśnienia press_temp->get_pressure(&cisnienie); //Odczytanie wartości temperatura printf("Manometr do kol\r\n"); hum_temp->read_id(&id);// Pobranie id czujnika temperatura z płytki rozszerzenia press_temp->read_id(&id); // Pobranie id czujnika ciśnienia z płytki rozszerzenia press_temp->get_pressure(&cisnienie); // Odczyt wartości ciśnienia z płytki rozszerzenia printf(" Cisnie atmosmeryczne: %7s hPa\r\n ",print_double(buffer1, cisnienie)); // Wyświetlenie wartości ciśnienia press_temp->get_temperature(&temperatura); // Odczytanie wartości temperatury z płytki rozszerzenia printf("Temp: %7s C\r\n ", print_double(buffer2,temperatura)); // Wyświetlenie wartości temperatury wzorzecP=230000; //Ciśnieni wzorcowe w kole wzorzecT=293; // Temeratura wzorcowa w Kelwinach Idealne_cisnienie=(((wzorzecP)*(temperatura+ 273))/(wzorzecT)); // coś liczymy wartość cisnienia pożądana w kole bary=Idealne_cisnienie/100000; // przeliczenie na bary z paskali ile=(bary-(cisnienie/1000)); // ile należy upuscić z koła printf("Ile ma byc w kole? %7s B\r\n ", print_double(buffer3,bary)); // Wartość ciśnienia jaka powinna znajdować się kole printf("Ile jest w kole? %7s B\r\n ", print_double(buffer1,cisnienie/1000)); // Wartość ciśnienia jak znaduje się w kole 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 ) { printf("Upusc %7s B\r\n ", print_double(buffer5,ile )); } else if ((cisnienie/1000)>=2.5 && (cisnienie/1000)<=2.7 ) // Jeżeli ciśnienie znaduje się w przedziale <2.5;2.7> { printf("Nic nie trzeba robić %7s B\r\n ", print_double(buffer5,ile )); } else if ((cisnienie/1000) > bary ) //Jeżeli ciśnienie ma wartość powyżej 2.7 { printf("dobij %7s B\r\n", print_double(buffer5,ile)); } }