Advertisement
Guest User

Untitled

a guest
Jun 5th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. void setup() {
  2. // Init ELM327
  3. const char* cmds[] = {"ATD\r", "ATZ\r", "ATE0\r", "ATL0\r", "ATS0\r", "ATH0\r", "ATSP0\r"};
  4. for (const char* cmd : cmds) {
  5. pRx->writeValue(cmd, strlen(cmd));
  6. delay(300);
  7. }
  8.  
  9. // Lecture baro initiale
  10. pRx->writeValue("0133\r", 6);
  11. delay(500);
  12. }
  13.  
  14. void loop() {
  15. static unsigned long lastRequest = 0;
  16. static unsigned long lastBaro = 0;
  17. unsigned long now = millis();
  18.  
  19. // Envoi MAP (010B) toutes les 50ms - mitraillette
  20. if (now - lastRequest > 50) {
  21. pRx->writeValue("010B\r", 6);
  22. lastRequest = now;
  23. }
  24.  
  25. // RequĂȘte BARO (0133) toutes les 60 secondes
  26. if (now - lastBaro > 60000) {
  27. pRx->writeValue("0133\r", 6);
  28. lastBaro = now;
  29. }
  30.  
  31. if (notificationReceived) {
  32. notificationReceived = false;
  33.  
  34. // Calcul boost PSI
  35. float boostPsi = (mapKpa - baroKpa) / 6.895f;
  36.  
  37. for (int i = 0; i < 4; i++) psi_older[i] = psi_older[i + 1];
  38. psi_older[4] = boostPsi;
  39.  
  40. float avgPsi = 0;
  41. for (int i = 0; i < 5; i++) avgPsi += psi_older[i];
  42. avgPsi /= 5;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement