Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 53.41 KB | None | 0 0
  1. // Bi-TripCo by Nick Stavrou
  2. // Bi-Fuel (LPG + Unleaded) Trip Computer
  3. // Metric version
  4. // Arduino UNO, 0.96" OLED display and DS3231 RTC module
  5. // Release date: 29 Mar 2017
  6. // Details can be found at www.instructables.com
  7.  
  8. // Libraries
  9. //#include "PinChangeInterrupt.h" // enables the interrupts at the other pin except the ones at the digital pins 2 and 3
  10. #include <avr/sleep.h>          // enables the sleep function
  11. #include <avr/power.h>          // power management
  12. #include <EEPROMex.h>           // enables some special functions for writing to and reading from EEPROM
  13. #include <EEPROMVar.h>
  14. #include <Wire.h>               // IIC LIBRARY
  15. #include "RTClib.h"             // Real Time Clock Library
  16. #include <math.h>               // enables complex math functions
  17. #include <Adafruit_ST7735.h>  // Include Adafruit_ST7735 library to drive the display
  18. #include <Adafruit_GFX.h>      
  19. #include <OneWire.h>
  20. #include <DallasTemperature.h>
  21. #include <movingAvg.h>        
  22.  
  23. #define OLED_RESET 4
  24. //Adafruit_SSD1306 display(OLED_RESET);
  25.  
  26. // Declare pins for the display:
  27. #define TFT_CS     30
  28. #define TFT_RST    28  // You can also connect this to the Arduino reset in which case, set this #define pin to -1!
  29. #define TFT_DC     26
  30. // The rest of the pins are pre-selected as the default hardware SPI for Arduino Uno (SCK = 51 and SDA = 52)
  31.  
  32. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
  33.  
  34. RTC_DS3231 rtc;
  35.  
  36. #define ONE_WIRE_BUS 22
  37. OneWire oneWire(ONE_WIRE_BUS);
  38. DallasTemperature sensors(&oneWire);
  39.  
  40. // variables declaration
  41. volatile static float vss_pulse_distance = 0.0003816033;  // distance coefficient -- change this according to your measurements (km/pulse)
  42. volatile float LPG_injector_flow;                        
  43. volatile static float unleadedFlow;            // gasoline injector flow coef. -- change this according to your measurements (litres/microseconds) = 0.00000001720
  44.  
  45. byte LPG1, LPG2, LPG3, LPG4, digitLPG, pos = 20;
  46. byte un1, un2, un3, un4, digitun, posi = 20;
  47. volatile unsigned long vss_pulses;
  48. volatile unsigned long last_speed_calculation_time;
  49. volatile float traveled_distance, traveled_distance2, traveled_distance3, seconds_passed, speed, avg_speed, distance_to_Unleadedstation;
  50. volatile float used_LPG, used_LPG2, instant_LPG_consumption, avg_LPG_consumption, Unleaded_in_tank, Full_tank = 45;
  51. volatile float used_Unleaded, used_Unleaded2, instant_unlead_consumption;
  52. volatile float average_L_100km_Unlead;
  53.  
  54.  
  55. volatile unsigned long unleadTime1=0, unleadTime2=0, unleadinj_Open_Duration=0;
  56. volatile unsigned long LPG_injector_open_duration = 0, injTime1=0, injTime2=0;
  57. int postemp;
  58. int vss_pin = 2; // VSS signal input at digital pin 2 (INT0)
  59. int LPG_pin = 3; // LPG injector signal input at digital pin 3 (INT1)
  60. int ignition_pin = 18; // ignition signal input
  61. int unleaded_pin = 19; // Unleaded injector signal input
  62.  
  63.  
  64. boolean buttonState, buttonState2;
  65. boolean lastButtonState2 = HIGH;
  66. long lastDebounceTime = 0, logohold, counter, counter2;
  67. volatile boolean ignition = false;
  68. boolean ignoreRelease = false;
  69. boolean inst_disp = true;
  70. byte menunumber = 0,  menunumbermax = 10;
  71. int h=0, m=0, s, m1;
  72. boolean timeRead = false, displaychange = true;
  73. //float thermReading, sensors.getTempCByIndex(0);
  74. boolean dots = true;
  75.  
  76. movingAvg speed1 (20);  //avereage speed for display
  77. movingAvg unleadconsumption (10); //avereage unleaded consumption for display
  78.  
  79. //Below are the variables declaration for the thermistor -- you can find more info at: https://learn.adafruit.com/thermistor/using-a-thermistor
  80. #define THERMISTORPIN A0
  81. #define THERMISTORNOMINAL 10000
  82. #define TEMPERATURENOMINAL 25  
  83.  
  84. #define NUMSAMPLES 5
  85. #define BCOEFFICIENT 3630
  86. #define SERIESRESISTOR 10000
  87. int samples[NUMSAMPLES];
  88. int i=0;
  89.  
  90. const unsigned char leaf [] PROGMEM= {
  91. 0x00, 0x00, 0x07, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x3F, 0xFC, 0x1E,
  92. 0x00, 0xFF, 0x80, 0x1C, 0x01, 0xFC, 0x00, 0x3C, 0x07, 0xF0, 0x00, 0x38, 0x0F, 0xC0, 0x00, 0x38,
  93. 0x1F, 0x00, 0x00, 0x70, 0x1E, 0x00, 0x00, 0x70, 0x3C, 0x00, 0x80, 0x70, 0x38, 0x03, 0xC0, 0x70,
  94. 0x70, 0x07, 0xC0, 0x70, 0xF0, 0x1F, 0x80, 0x70, 0xF0, 0x1E, 0x00, 0x70, 0xE0, 0x3E, 0x00, 0x70,
  95. 0xE0, 0x78, 0x00, 0x70, 0xE0, 0xF0, 0x00, 0xF0, 0xE1, 0xE0, 0x00, 0xF0, 0xE3, 0xE0, 0x00, 0xE0,
  96. 0xE3, 0x80, 0x00, 0xE0, 0xE7, 0x80, 0x01, 0xE0, 0xEF, 0x00, 0x03, 0xE0, 0xEE, 0x00, 0x03, 0xC0,
  97. 0xFE, 0x00, 0x07, 0x80, 0x7C, 0x00, 0x1F, 0x00, 0x7C, 0x00, 0xFE, 0x00, 0x3D, 0xFF, 0xFC, 0x00,
  98. 0x39, 0xFF, 0xF0, 0x00, 0x70, 0xFE, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00
  99. };
  100.  
  101. const unsigned char  dist_to_LPG [] PROGMEM= {
  102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00,
  103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00,
  104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00,
  105. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0E, 0x20,
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0E, 0x70,
  107. 0x00, 0x00, 0x3F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0E, 0x38,
  108. 0x00, 0x01, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0E, 0x1C,
  109. 0x00, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0E, 0x0C,
  110. 0x00, 0x3F, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0F, 0x8C,
  111. 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0F, 0x8C,
  112. 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x0F, 0x8C,
  113. 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C,
  114. 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x60, 0x06, 0x00, 0x01, 0xFF, 0xFF, 0x8C,
  115. 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x78, 0x07, 0x80, 0x01, 0xFF, 0xFF, 0x8C,
  116. 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x1E, 0x01, 0xE0, 0x01, 0xFF, 0xFF, 0x8C,
  117. 0x7F, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xFC, 0x00, 0x07, 0x80, 0x78, 0x01, 0xFF, 0xFF, 0x8C,
  118. 0x7F, 0xCF, 0x3F, 0xFF, 0xFF, 0xFE, 0x79, 0xFE, 0x00, 0x01, 0xE0, 0x1E, 0x01, 0xFF, 0xFF, 0x8C,
  119. 0x7F, 0x9F, 0xBF, 0xFF, 0xFF, 0xFC, 0xFD, 0xFE, 0x00, 0x00, 0x60, 0x06, 0x01, 0xFF, 0xFF, 0x8C,
  120. 0x3F, 0xBF, 0xDF, 0xFF, 0xFF, 0xFD, 0xFE, 0xFC, 0x00, 0x01, 0xE0, 0x1E, 0x01, 0xFF, 0xFF, 0x8C,
  121. 0x3F, 0x3F, 0xDF, 0xFF, 0xFF, 0xF9, 0xFE, 0xFC, 0x00, 0x07, 0x80, 0x78, 0x01, 0xFF, 0xFF, 0x8C,
  122. 0x0F, 0x7F, 0xDF, 0xFF, 0xFF, 0xFB, 0xFE, 0xFC, 0x00, 0x1E, 0x01, 0xE0, 0x01, 0xFF, 0xFF, 0x8C,
  123. 0x00, 0x3F, 0xCF, 0xFF, 0xFF, 0xF9, 0xFE, 0x70, 0x00, 0x78, 0x07, 0x80, 0x01, 0xFF, 0xFF, 0x8C,
  124. 0x00, 0x3F, 0xC0, 0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x60, 0x06, 0x00, 0x01, 0xFF, 0xFF, 0x8C,
  125. 0x00, 0x1F, 0x80, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C,
  126. 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0xFC,
  127. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0xF8,
  128. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00,
  129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00,
  130. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0,
  131. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0,
  132. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0,
  133. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0
  134. };
  135.  
  136. const unsigned char  average [] PROGMEM= {
  137. 0x00, 0x00, 0x07, 0xCE, 0x1F, 0xFE, 0x3F, 0xFE, 0x7C, 0x7C, 0x70, 0xFC, 0xF1, 0xFE, 0xE3, 0xEE,
  138. 0xE7, 0xCE, 0xEF, 0x8E, 0xFF, 0x1E, 0x7E, 0x1C, 0x7C, 0x7C, 0xFF, 0xF8, 0xFF, 0xF0, 0xE7, 0xC0
  139. };
  140.  
  141. const unsigned char averagecons [] PROGMEM= {
  142. 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x07, 0xCE, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x00,
  143. 0x1F, 0xFE, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x3F, 0xFE, 0x01, 0xC0, 0x0E, 0x20, 0x00, 0x00,
  144. 0x7C, 0x7C, 0x01, 0xC0, 0x0E, 0x70, 0x00, 0x00, 0x70, 0xFC, 0x01, 0xC0, 0x0E, 0x38, 0x00, 0x00,
  145. 0xF1, 0xFE, 0x01, 0xC0, 0x0E, 0x1C, 0x00, 0x00, 0xE3, 0xEE, 0x01, 0xC0, 0x0E, 0x0C, 0x00, 0x00,
  146. 0xE7, 0xCE, 0x01, 0xC0, 0x0F, 0x8C, 0x00, 0x00, 0xEF, 0x8E, 0x01, 0xC0, 0x0F, 0x8C, 0x00, 0x00,
  147. 0xFF, 0x1E, 0x01, 0xC0, 0x0F, 0x8C, 0x00, 0x00, 0x7E, 0x1C, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00,
  148. 0x7C, 0x7C, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00, 0xFF, 0xF8, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00,
  149. 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00, 0xE7, 0xC0, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00,
  150. 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00,
  151. 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00,
  152. 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00,
  153. 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x8C, 0x00, 0x00,
  154. 0x00, 0x00, 0x01, 0xFF, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0xF8, 0x00, 0x00,
  155. 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x00,
  156. 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0, 0x00, 0x00,
  157. 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xC0, 0x00, 0x00
  158. };
  159. const unsigned char avspeed [] PROGMEM = {
  160. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  161. 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0x80, 0x00, 0x00,
  162. 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x6F, 0xF0, 0x00, 0x00,
  163. 0x00, 0x00, 0x01, 0xF0, 0x60, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x60, 0x3C, 0x00, 0x00,
  164. 0x07, 0xCE, 0x07, 0x80, 0x60, 0x3E, 0x00, 0x00, 0x1F, 0xFE, 0x0F, 0x00, 0x00, 0x7F, 0x00, 0x00,
  165. 0x3F, 0xFE, 0x0E, 0x30, 0x00, 0xE7, 0x00, 0x00, 0x7C, 0x7C, 0x1E, 0x38, 0x00, 0xC7, 0x80, 0x00,
  166. 0x70, 0xFC, 0x1C, 0x1E, 0x00, 0x03, 0x80, 0x00, 0xF1, 0xFE, 0x1C, 0x0F, 0x00, 0x03, 0x80, 0x00,
  167. 0xE3, 0xEE, 0x3C, 0x0F, 0xC0, 0x03, 0xC0, 0x00, 0xE7, 0xCE, 0x38, 0x07, 0xF0, 0x01, 0xC0, 0x00,
  168. 0xEF, 0x8E, 0x38, 0x03, 0xF8, 0x01, 0xC0, 0x00, 0xFF, 0x1E, 0x3F, 0x03, 0xF8, 0x0F, 0xC0, 0x00,
  169. 0x7E, 0x1C, 0x3F, 0x01, 0xF8, 0x0F, 0xC0, 0x00, 0x7C, 0x7C, 0x38, 0x01, 0xF0, 0x01, 0xC0, 0x00,
  170. 0xFF, 0xF8, 0x38, 0x00, 0xE0, 0x01, 0xC0, 0x00, 0xFF, 0xF0, 0x3C, 0x00, 0x00, 0x03, 0xC0, 0x00,
  171. 0xE7, 0xC0, 0x1C, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x03, 0x80, 0x00,
  172. 0x00, 0x00, 0x1E, 0x30, 0x00, 0xC7, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x70, 0x00, 0xE7, 0x00, 0x00,
  173. 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFE, 0x00, 0x00,
  174. 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  175. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  176. };
  177. const unsigned char dist [] PROGMEM= {
  178. 0x00, 0x39, 0x9C, 0x00, 0x00, 0x39, 0x9C, 0x00, 0x00, 0x71, 0x8E, 0x00, 0x00, 0x71, 0x8E, 0x00,
  179. 0x00, 0x71, 0x8E, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0xE1, 0x87, 0x00,
  180. 0x01, 0xC1, 0x83, 0x80, 0x01, 0xC1, 0x83, 0x80, 0x01, 0xC1, 0x83, 0x80, 0x03, 0x81, 0x81, 0xC0,
  181. 0x03, 0x81, 0x81, 0xC0, 0x03, 0x81, 0x81, 0xC0, 0x07, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0xE0,
  182. 0x07, 0x01, 0x80, 0xE0, 0x0E, 0x01, 0x80, 0x70, 0x0E, 0x01, 0x80, 0x70, 0x0E, 0x01, 0x80, 0x70,
  183. 0x1C, 0x01, 0x80, 0x38, 0x1C, 0x01, 0x80, 0x38, 0x1C, 0x01, 0x80, 0x38, 0x38, 0x00, 0x00, 0x1C,
  184. 0x38, 0x00, 0x00, 0x1C, 0x38, 0x01, 0x80, 0x1C, 0x70, 0x01, 0x80, 0x0E, 0x70, 0x01, 0x80, 0x0E,
  185. 0x70, 0x01, 0x80, 0x0E, 0xE0, 0x01, 0x80, 0x07, 0xE0, 0x01, 0x80, 0x07, 0xE0, 0x01, 0x80, 0x07
  186. };
  187. const unsigned char Unleaded_fill_nozzle [] PROGMEM= {
  188. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x1F, 0xF0, 0x00,
  189. 0x00, 0x1F, 0xFF, 0xE0, 0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x3F, 0xF8, 0x18, 0x00, 0x71, 0xF0, 0x00,
  190. 0x00, 0xEF, 0xE0, 0x00, 0x01, 0xD1, 0xC0, 0x08, 0x07, 0xE1, 0x80, 0x08, 0x07, 0x82, 0x00, 0x1C,
  191. 0x0E, 0xC6, 0x00, 0x1C, 0x18, 0x6C, 0x00, 0x3E, 0x10, 0x38, 0x00, 0x3E, 0x30, 0x00, 0x00, 0x1E,
  192. 0x30, 0x00, 0x00, 0x08, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
  193. 0x30, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
  194. 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  195. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  196. };
  197.  
  198. const unsigned char  logo [] PROGMEM= {
  199. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  200. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  201. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  202. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  203. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  204. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  205. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  206. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  207. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC7, 0xDF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  208. 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x9F, 0xB8, 0x00, 0x2C, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
  209. 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x80, 0x00, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00,
  210. 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00,
  211. 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x03, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00,
  212. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x00, 0x01, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00,
  213. 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x60, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  214. 0x00, 0x00, 0x00, 0x00, 0x0A, 0x01, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x30, 0x00, 0x00, 0x00, 0x00,
  215. 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xE0, 0x00, 0x00, 0x03, 0xC0, 0x10, 0x00, 0x00, 0x00, 0x00,
  216. 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xE0, 0x00, 0x00, 0x03, 0xC0, 0x18, 0x00, 0x00, 0x00, 0x00,
  217. 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xF0, 0x00, 0x00, 0x05, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00,
  218. 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0xF0, 0x00, 0x00, 0x04, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00,
  219. 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0xF0, 0x00, 0x00, 0x08, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  220. 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0xF0, 0x00, 0x00, 0x07, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00,
  221. 0x00, 0x00, 0x00, 0x00, 0x1C, 0x01, 0xF8, 0x00, 0x00, 0x0D, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00,
  222. 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0xF8, 0x00, 0x00, 0x0B, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00,
  223. 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0xF8, 0x00, 0x00, 0x1B, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00,
  224. 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0xF0, 0x00, 0x00, 0x13, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  225. 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xF0, 0x00, 0x00, 0x1F, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00,
  226. 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xF4, 0x00, 0x00, 0x17, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
  227. 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xF8, 0x00, 0x00, 0x34, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
  228. 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xF8, 0x00, 0x00, 0x3F, 0x80, 0x0C, 0x00, 0x00, 0x00, 0x00,
  229. 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xF4, 0x00, 0x00, 0x3F, 0x80, 0x0C, 0x00, 0x00, 0x00, 0x00,
  230. 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0xF2, 0x00, 0x00, 0x3F, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00,
  231. 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xF0, 0x00, 0x00, 0x3D, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00,
  232. 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0xFF, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  233. 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0xFF, 0x00, 0x00, 0xFD, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
  234. 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xFF, 0x80, 0x01, 0xFD, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00,
  235. 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xFF, 0xC0, 0x03, 0xBE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  236. 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xFF, 0x60, 0x07, 0xFD, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00,
  237. 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xFF, 0x4F, 0x2F, 0xFF, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00,
  238. 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xFF, 0xD3, 0xEB, 0xFE, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00,
  239. 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x4F, 0x9A, 0x0B, 0x3C, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00,
  240. 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x6F, 0xA0, 0x03, 0xFE, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
  241. 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x7F, 0x00, 0x00, 0xFE, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
  242. 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x5F, 0x80, 0x00, 0xFE, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
  243. 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x3F, 0x80, 0x01, 0xFD, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
  244. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6F, 0x80, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  245. 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x6F, 0x00, 0x00, 0x3C, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
  246. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x7E, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00,
  247. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x35, 0x00, 0x00, 0x7C, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
  248. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x7C, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
  249. 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x6E, 0x00, 0x00, 0x7C, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00,
  250. 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x22, 0x00, 0x00, 0x14, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
  251. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
  252. 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x90, 0x00, 0x00, 0x06, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
  253. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xDF, 0xF8, 0x1F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
  254. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x6F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  255. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  256. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  257. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  258. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  259. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  260. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  261. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  262. 0x00, 0x00, 0x00, 0x00, 0x01, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  263. 0x00, 0x23, 0xE2, 0x7F, 0x0A, 0x3B, 0x03, 0xE8, 0x15, 0x69, 0x72, 0xD0, 0x0C, 0xFC, 0x00, 0x00,
  264. 0x00, 0x0A, 0x80, 0x70, 0x03, 0x03, 0x20, 0xF8, 0x02, 0x82, 0x2C, 0x2C, 0x03, 0xF4, 0x00, 0x00,
  265. 0x00, 0x06, 0x80, 0x28, 0x2A, 0x03, 0xC0, 0x97, 0x00, 0x03, 0xC0, 0x22, 0x01, 0x02, 0x00, 0x00,
  266. 0x00, 0x06, 0x80, 0x28, 0x18, 0x01, 0x20, 0x09, 0xC0, 0x03, 0xC0, 0x17, 0x03, 0x08, 0x00, 0x00,
  267. 0x00, 0x06, 0x80, 0x28, 0x6C, 0x00, 0x50, 0xC9, 0xC0, 0x03, 0xC0, 0x0F, 0x04, 0x03, 0x80, 0x00,
  268. 0x00, 0x07, 0x9D, 0xE8, 0x34, 0x01, 0x90, 0x83, 0xE0, 0x03, 0xC0, 0x02, 0x06, 0x07, 0xC0, 0x00,
  269. 0x00, 0x05, 0xBF, 0x50, 0x74, 0x01, 0xA0, 0x03, 0x50, 0x03, 0x00, 0x0E, 0x02, 0x05, 0x80, 0x00,
  270. 0x00, 0x04, 0x00, 0x10, 0x7C, 0x00, 0x50, 0x00, 0xD8, 0x03, 0xE0, 0x11, 0x10, 0x08, 0xE0, 0x00,
  271. 0x00, 0x05, 0x80, 0x50, 0x58, 0x01, 0xB0, 0x80, 0x30, 0x03, 0xC0, 0x01, 0x04, 0x01, 0x20, 0x00,
  272. 0x00, 0x04, 0x00, 0x7C, 0x17, 0x06, 0x20, 0xC0, 0x7E, 0x00, 0xBF, 0xA8, 0x30, 0x01, 0xF0, 0x00,
  273. 0x00, 0x17, 0x60, 0xBE, 0x06, 0x32, 0x42, 0xF8, 0x3D, 0x06, 0x7F, 0xB8, 0xD4, 0x05, 0xE4, 0x00,
  274. 0x00, 0x19, 0x43, 0x03, 0x03, 0x36, 0x03, 0xB8, 0x23, 0x07, 0x80, 0x00, 0x24, 0x00, 0x04, 0x00,
  275. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  276. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  277. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  278. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  279. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  280. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  281. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  282. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  283. };
  284.  
  285. const unsigned char FuelTank [] PROGMEM = {
  286. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80,
  287. 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8,
  288. 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E,
  289. 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E,
  290. 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E,
  291. 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E,
  292. 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E,
  293. 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xEF, 0x00, 0x01, 0xE0, 0x00, 0x3C, 0x00, 0x0E,
  294. 0xFF, 0xF0, 0x07, 0xFE, 0x00, 0xFF, 0xC0, 0x1E, 0xFF, 0xFC, 0x0F, 0xFF, 0x81, 0xFF, 0xF0, 0x3E,
  295. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
  296. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
  297. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
  298. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
  299. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC,
  300. 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0,
  301. 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  302. };
  303.  
  304. const unsigned char petrolstationpump [] PROGMEM = {
  305. 0x03, 0xFF, 0xFC, 0x00, 0x03, 0xFF, 0xFC, 0x00, 0x03, 0xFF, 0xFC, 0x00, 0x03, 0x80, 0x1C, 0x40,
  306. 0x03, 0x80, 0x1C, 0xE0, 0x03, 0x80, 0x1C, 0x70, 0x03, 0x80, 0x1C, 0x38, 0x03, 0x80, 0x1C, 0x18,
  307. 0x03, 0x80, 0x1F, 0x18, 0x03, 0x80, 0x1F, 0x18, 0x03, 0x80, 0x1F, 0x18, 0x03, 0xFF, 0xFF, 0x18,
  308. 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18,
  309. 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18,
  310. 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18, 0x03, 0xFF, 0xFF, 0x18,
  311. 0x03, 0xFF, 0xFD, 0xF8, 0x03, 0xFF, 0xFD, 0xF0, 0x03, 0xFF, 0xFC, 0x00, 0x03, 0xFF, 0xFC, 0x00,
  312. 0x1F, 0xFF, 0xFF, 0x80, 0x1F, 0xFF, 0xFF, 0x80, 0x1F, 0xFF, 0xFF, 0x80, 0x1F, 0xFF, 0xFF, 0x80
  313. };
  314.  
  315. const unsigned char speedometer [] PROGMEM = {
  316. 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x7F, 0xFE, 0x00, 0x00, 0xFF, 0xFF, 0x00,
  317. 0x03, 0xFD, 0xBF, 0xC0, 0x07, 0xC1, 0x83, 0xE0, 0x0F, 0x01, 0x80, 0xF0, 0x1E, 0x01, 0x80, 0xF8,
  318. 0x3C, 0x00, 0x01, 0xFC, 0x38, 0xC0, 0x03, 0x9C, 0x78, 0xE0, 0x03, 0x1E, 0x70, 0x78, 0x00, 0x0E,
  319. 0x70, 0x3C, 0x00, 0x0E, 0xF0, 0x3F, 0x00, 0x0F, 0xE0, 0x1F, 0xC0, 0x07, 0xE0, 0x0F, 0xE0, 0x07,
  320. 0xFC, 0x0F, 0xE0, 0x3F, 0xFC, 0x07, 0xE0, 0x3F, 0xE0, 0x07, 0xC0, 0x07, 0xE0, 0x03, 0x80, 0x07,
  321. 0xF0, 0x00, 0x00, 0x0F, 0x70, 0x00, 0x00, 0x0E, 0x70, 0x00, 0x00, 0x0E, 0x78, 0xC0, 0x03, 0x1E,
  322. 0x39, 0xC0, 0x03, 0x9C, 0x3F, 0x80, 0x01, 0xFC, 0x1F, 0xFF, 0xFF, 0xF8, 0x0F, 0xFF, 0xFF, 0xF0,
  323. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  324. };
  325.  
  326. const unsigned char snowflake [] PROGMEM = {
  327. 0x01, 0x80, 0x07, 0xE0, 0x13, 0xC8, 0xD1, 0x8B, 0xF9, 0x9F, 0x39, 0x9C, 0xFF, 0xFF, 0x07, 0xE0,
  328. 0x07, 0xE0, 0xFF, 0xFF, 0x39, 0x9C, 0xF9, 0x9F, 0xD1, 0x8B, 0x13, 0xC8, 0x07, 0xE0, 0x01, 0x80
  329. };
  330.  
  331. void setup()
  332. {
  333.  
  334.    // start serial port
  335.  Serial.begin(9600);
  336.  sensors.begin();
  337.  speed1.begin();
  338.  unleadconsumption.begin();
  339.  Serial.println(seconds_passed++);
  340.  
  341.  // Display setup:
  342.  
  343.   // Use this initializer if you're using a 1.8" TFT
  344.   tft.initR(INITR_BLACKTAB);  // Initialize a ST7735S chip, black tab
  345.   tft.setRotation(1);
  346.   tft.setTextWrap(false);  // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
  347.                            // To override this behavior (so text will run off the right side of the display - useful for
  348.                            // scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
  349.                            // with setTextWrap(true).
  350.  
  351.  
  352.   pinMode(24, OUTPUT); //wygaszenie podświetlenia
  353.   pinMode(34, INPUT); // Button 2
  354.   pinMode(32, INPUT); // Button 1
  355.  
  356.   pinMode(vss_pin, INPUT);
  357.   pinMode(LPG_pin, INPUT);
  358.   pinMode(ignition_pin, INPUT);
  359.   pinMode(unleaded_pin, INPUT);
  360.  
  361.   // below recalls the values stored in case of power loss
  362.   traveled_distance = EEPROM.readFloat(0);
  363.   traveled_distance2 = EEPROM.readFloat (5);
  364.   used_LPG = EEPROM.readFloat (10);
  365.   used_LPG2 = EEPROM.readFloat(15);
  366.   Unleaded_in_tank = EEPROM.readFloat(20);
  367.   seconds_passed = EEPROM.readFloat(25);
  368.   used_Unleaded = EEPROM.readFloat(30);
  369.   traveled_distance3 = EEPROM.readFloat (35);
  370.   used_Unleaded2 = EEPROM.readFloat(45);
  371.   LPG1 = EEPROM.readByte (40);
  372.   LPG2 = EEPROM.readByte (41);
  373.   LPG3 = EEPROM.readByte (42);
  374.   LPG4 = EEPROM.readByte (43);
  375.   LPG_injector_flow = (LPG1 * 1000 + LPG2 * 100 + LPG3 * 10 + LPG4) * 1e-11;
  376. // unleaded
  377.   un1 = EEPROM.readByte (50);
  378.   un2 = EEPROM.readByte (51);
  379.   un3 = EEPROM.readByte (52);
  380.   un4 = EEPROM.readByte (53);
  381.   unleadedFlow = (un1 * 1000 + un2 * 100 + un3 * 10 + un4) * 1e-11;
  382.  
  383.   noInterrupts();
  384.   //set and initialize the TIMER1
  385.  
  386.     TCCR1A = 0;            // undo the Arduino's timer configuration
  387.     TCCR1B = 0;            // ditto
  388.     TCNT1  = 0;            // reset timer
  389.     OCR1A  = 62500 - 1;    // period = 62500 clock tics
  390.     TCCR1B = _BV(WGM12)    // CTC mode, TOP = OCR1A
  391.            | _BV(CS12);    // clock at F_CPU/256
  392.     TIMSK1 = _BV(OCIE1A);  // interrupt on output compare A
  393.  
  394.  
  395.   attachInterrupt(digitalPinToInterrupt(ignition_pin), ignitionSignal, CHANGE);
  396.  
  397.   last_speed_calculation_time = millis();
  398.  
  399.   interrupts();
  400.   delay(10);
  401. }
  402.  
  403. void loop()
  404.  
  405.   {// When the ignition switch is turned, executes the next two ifs
  406.   if (ignition == true && digitalRead(18) == LOW)
  407.   {
  408.       detachInterrupt(digitalPinToInterrupt(vss_pin));
  409.       detachInterrupt(digitalPinToInterrupt(LPG_pin));
  410.       detachInterrupt(digitalPinToInterrupt(unleaded_pin));
  411.       delay(50);
  412.       ignition = false;
  413.       if (menunumber == 11)
  414.       {  
  415.             EEPROM.writeByte(40, LPG1); //stores the new LPG coef.
  416.             EEPROM.writeByte(41, LPG2);
  417.             EEPROM.writeByte(42, LPG3);
  418.             EEPROM.writeByte(43, LPG4);
  419.          LPG_injector_flow = (LPG1 * 1000 + LPG2 * 100 + LPG3 * 10 + LPG4) * 1e-11;
  420.          inst_disp = true;
  421.          tft.fillScreen(ST7735_BLACK);
  422.          menunumber = 0;
  423.        
  424.       }
  425.       if (menunumber == 12) // same as previous for "Time Set" menu
  426.       {
  427.         DateTime dt = rtc.now();
  428.         s = dt.second();
  429.         if (m != m1) s = (((millis() - counter)/1000))%60;
  430.         else s = dt.second(), m = dt.minute();
  431.         rtc.adjust(DateTime(dt.year(), dt.month(), dt.day(), h, m, s));
  432.         ignoreRelease = true;
  433.         lastButtonState2 = LOW;
  434.         menunumber = 10;
  435.         tft.fillScreen(ST7735_BLACK);
  436.       }
  437.       if (menunumber == 13)
  438.       {
  439.             EEPROM.writeByte(50, un1); //stores the new unleaded coef.
  440.             EEPROM.writeByte(51, un2);
  441.             EEPROM.writeByte(52, un3);
  442.             EEPROM.writeByte(53, un4);
  443.         unleadedFlow = (un1 * 1000 + un2 * 100 + un3 * 10 + un4) * 1e-11;
  444.         inst_disp = true;
  445.         tft.fillScreen(ST7735_BLACK);
  446.         menunumber = 2;
  447.       }
  448.  
  449.      
  450.       // when the ignition switched off it stores the values to the EEPROM
  451.       EEPROM.writeFloat (0, traveled_distance);
  452.       EEPROM.writeFloat (5, traveled_distance2);
  453.       EEPROM.writeFloat (10, used_LPG);
  454.       EEPROM.writeFloat (15, used_LPG2);
  455.       EEPROM.writeFloat (20, Unleaded_in_tank);
  456.       EEPROM.writeFloat (25, seconds_passed);
  457.       EEPROM.writeFloat (30, used_Unleaded);
  458.       EEPROM.writeFloat (35, traveled_distance3);
  459.       EEPROM.writeFloat (45, used_Unleaded2);
  460.       digitalWrite(24, HIGH); //podswietlenie
  461.       //display.ssd1306_command(SSD1306_DISPLAYOFF);
  462.       tft.sleep();
  463.      
  464.       tft.fillScreen(ST7735_BLACK);
  465.       sleep_enable(); // enables the sleep mode
  466.       set_sleep_mode(SLEEP_MODE_PWR_DOWN); // set the sleep mode
  467.       cli();
  468.       //sleep_bod_disable(); // disables the brown out detector to consume less power while sleeping
  469.       sei();
  470.       sleep_mode(); // microcontroller goes to sleep  
  471.   }
  472.   // when it wakes up continues from here -- also the first time we turn the ignition key to ON starts from here
  473.   if (ignition == true && digitalRead(18) == HIGH)
  474.   {
  475.      
  476.       digitalWrite(24, LOW);
  477.       ignition = false;    // this variable is needed in order to run once the code inside this if
  478.       logohold = millis(); // hold the LOGO screen on, for 2 sec
  479.       inst_disp = true;
  480.      
  481.       //display.begin(SSD1306_SWITCHCAPVCC, 0x3C);          
  482.       tft.wake();
  483.      
  484.       tft.fillScreen(ST7735_BLACK);                              
  485.       tft.drawBitmap(15, 0,  logo, 128, 84, ST7735_RED);    
  486.       delay(5000);
  487.       tft.fillScreen(ST7735_BLACK);                                        
  488.  
  489.       attachInterrupt(digitalPinToInterrupt(vss_pin), distance, RISING); // attaches the interrupt which related to the VSS signal
  490.       attachInterrupt(digitalPinToInterrupt(LPG_pin), LPG_injector_time, CHANGE); // interrupt for LPG injector signal
  491.       attachInterrupt(digitalPinToInterrupt(unleaded_pin), UnleadedTime, CHANGE); // petrol injector signal input and interrupt
  492.       while (millis() - logohold < 2000) ;
  493.                                            
  494.  
  495.   }
  496.  
  497.     // every 5sec calculates average LPG consumption, remaining distance accordingly to the calculated remaining fuel in tank, average speed and average Unleaded cons.
  498.   if(millis()%5000 < 50)
  499.     {
  500.     avg_LPG_consumption = 100 * used_LPG2/traveled_distance2;
  501.     distance_to_Unleadedstation = 100 * Unleaded_in_tank/average_L_100km_Unlead;  
  502.     avg_speed = (traveled_distance3 / seconds_passed)*3600;          
  503.     average_L_100km_Unlead = 100 * used_Unleaded2/traveled_distance2;
  504.     }
  505.  
  506.    
  507.     volatile  float avgspeed1 = speed1.reading(speed);   // calculate the moving average
  508.     volatile  float avginstantunleadconsumption = unleadconsumption.reading(instant_unlead_consumption);   // calculate the moving average
  509.  
  510. // For the short and long press function I consulted: http://jmsarduino.blogspot.gr/2009/05/click-for-press-and-hold-for-b.html
  511. // There are many differences though
  512. // "button 1" -- only  SHORT PRESS function -- changes occur on press, because there is no LONG PRESS function
  513.     if (digitalRead(32) != buttonState) {
  514.       buttonState = digitalRead(32);      
  515.       if (buttonState == LOW)            
  516.       {                        
  517.       if (menunumber <= menunumbermax){ // changes the display indications forwards
  518.       if (menunumber == menunumbermax) menunumber =0;
  519.       else menunumber += 1;
  520.       tft.fillScreen(ST7735_BLACK);
  521.       }
  522.       if (menunumber == 12) //if we are at the "Time Set" menu it changes the Hour
  523.       {
  524.         if (h < 23) h += 1, counter = millis();
  525.         else h = 0, counter = millis();
  526.       }
  527.       // if we are at the "LPG Coef." menu it changes the LPG_injector_flow digits
  528.         if (menunumber == 11 && digitLPG == 1){
  529.           if (LPG1 < 9) LPG1 += 1, counter = millis();
  530.           else LPG1 = 0, counter = millis();
  531.         }
  532.         if (menunumber == 11 && digitLPG == 2){
  533.           if (LPG2 < 9) LPG2 += 1, counter = millis();
  534.           else LPG2 = 0, counter = millis();
  535.         }
  536.         if (menunumber == 11 && digitLPG == 3){
  537.           if (LPG3 < 9) LPG3 += 1, counter = millis();
  538.           else LPG3 = 0, counter = millis();
  539.         }
  540.         if (menunumber == 11 && digitLPG == 4){
  541.           if (LPG4 < 9) LPG4 += 1,  counter = millis();
  542.           else LPG4 = 0, counter = millis();
  543.         }
  544.       // if we are at the "unleaded Coef." menu it changes the unleadedFlow digits
  545.         if (menunumber == 13 && digitun == 1){
  546.           if (un1 < 9) un1 += 1, counter = millis();
  547.           else un1 = 0, counter = millis();
  548.         }
  549.         if (menunumber == 13 && digitun == 2){
  550.           if (un2 < 9) un2 += 1, counter = millis();
  551.           else un2 = 0, counter = millis();
  552.         }
  553.         if (menunumber == 13 && digitun == 3){
  554.           if (un3 < 9) un3 += 1, counter = millis();
  555.           else un3 = 0, counter = millis();
  556.         }
  557.         if (menunumber == 13 && digitun == 4){
  558.           if (un4 < 9) un4 += 1,  counter = millis();
  559.           else un4 = 0, counter = millis();
  560.         }
  561.      
  562.      
  563.       }
  564.     }
  565.  
  566. ////////// "button 2" functions /////////////////
  567. buttonState2 = digitalRead(34);
  568. if (buttonState2 == LOW && lastButtonState2 == HIGH) lastDebounceTime = millis(); //keeps the time that button2 pressed
  569.  
  570. if (buttonState2 == HIGH && lastButtonState2 == LOW)
  571. {
  572. if (ignoreRelease == false) // "button 2" SHORT PRESS functions -- on release
  573.   {
  574.   if (menunumber <= menunumbermax)
  575.       {   if (menunumber == 0) menunumber = menunumbermax;
  576.           else menunumber = menunumber - 1;
  577.       tft.fillScreen(ST7735_BLACK);
  578.       }
  579.   if (menunumber == 12)  
  580.       {  if (m < 59) m=m+1, counter = millis();
  581.          else m = 0, counter = millis();
  582.      
  583.       }
  584.   if (menunumber == 11) // LPG coef. setting menu -- "button 2" short press changes the position of the cursor
  585.       { pos += 20;
  586.         digitLPG += 1;
  587.         counter = millis();
  588.         if (digitLPG == 5)
  589.           { pos = 20;
  590.             digitLPG = 1;
  591.           }
  592.       }
  593.   if (menunumber == 13) // unleaded Coef. setting menu -- "button 2" short press changes the position of the cursor
  594.       { posi += 20;
  595.         digitun += 1;
  596.         counter = millis();
  597.         if (digitun == 5)
  598.           { posi = 20;
  599.             digitun = 1;
  600.           }
  601.       }
  602.   }
  603. else ignoreRelease = false;
  604. }
  605. //////////////////// "button 2" LONG PRESS functions /////////////////////////////////////////////////////
  606. if (digitalRead(34) == HIGH) displaychange = true;  
  607. if (buttonState2 == LOW && (millis() - lastDebounceTime) > 3000 && displaychange == true) // below are the long press functions for button 2
  608. {
  609.       if (menunumber == 0) menunumber = 11, counter = millis(), counter2 = millis(), displaychange = false, digitLPG = 1,  tft.fillScreen(ST7735_BLACK); //goes to the "LPG Coef." menu
  610.       if (menunumber == 1) traveled_distance2 = 0, used_LPG2 = 0, avg_LPG_consumption = 0, used_Unleaded2 = 0,  tft.fillScreen(ST7735_BLACK);// average LPG consumption and average Unleaeded cons. reset
  611.       if (menunumber == 2) menunumber = 13, counter = millis(), counter2 = millis(), displaychange = false, digitun = 1,  tft.fillScreen(ST7735_BLACK);//goes to the "Unleaded Coef." menu
  612.       if (menunumber == 3) traveled_distance3 = 0, seconds_passed = 0, avg_speed = 0,  tft.fillScreen(ST7735_BLACK); // average speed reset
  613.       if (menunumber == 4) traveled_distance = 0,  tft.fillScreen(ST7735_BLACK); //traveled Distance = 0
  614.       if (menunumber == 6) used_LPG = 0,  tft.fillScreen(ST7735_BLACK); // total LPG litres = 0
  615.       if (menunumber == 7) Unleaded_in_tank = Full_tank,  tft.fillScreen(ST7735_BLACK); // LPG tank reset to full
  616.       if (menunumber == 8) used_Unleaded = 0,  tft.fillScreen(ST7735_BLACK); // total unleaded fuel reset
  617.       if (menunumber == 9) traveled_distance2 = 0, used_LPG2 = 0, avg_LPG_consumption = 0, used_Unleaded2 = 0,  tft.fillScreen(ST7735_BLACK); // same with menunumber = 1
  618.       if (menunumber == 10) menunumber = 12, counter = millis(), counter2 = millis(), timeRead = true, displaychange = false,  tft.fillScreen(ST7735_BLACK); //goes to the "Time Setting" menu
  619.  
  620. ignoreRelease = true;
  621. }
  622. lastButtonState2 = buttonState2;
  623.  
  624. // below are the misc screens
  625. switch (menunumber)
  626. {
  627.     case 0:
  628. cons1:  
  629.        
  630.         if(inst_disp == true) displaychange = false, inst_disp = false, digitLPG = 0, pos = 20;
  631.         tft.setTextColor(ST7735_GREEN,     ST7735_BLACK);
  632.         //tft.drawBitmap(20, 20,  petrolstationpump, 32, 32, ST7735_BLUE);
  633.         //tft.setCursor(60, 30);
  634.         //tft.setTextSize(1);
  635.         //tft.print(F("LPG"));
  636.         tft.setCursor(58,35);
  637.         tft.setTextSize(1);
  638.         if (speed > 2)
  639.         {tft.print(F("L/ "));
  640.          tft.setCursor(58,43);
  641.          tft.setTextSize(1);
  642.          tft.print(F("100"));}
  643.         else tft.print(F("L/H")); //when the car is stopped displays the instant consumption in l/h
  644.         tft.setCursor(10,36);
  645.         tft.setTextSize(2);
  646.         if(avginstantunleadconsumption > 99.9) tft.print(F("99.9"));
  647.         else tft.print(avginstantunleadconsumption  , 1);
  648.        
  649.         tft.setCursor(10,63);
  650.         tft.setTextSize(2.5);
  651.         if (speed > 2){
  652.           if(average_L_100km_Unlead > 99.9) tft.print(F("99.9"));
  653.           else tft.print(average_L_100km_Unlead  , 1);}
  654.         else
  655.         tft.print(used_Unleaded  , 1);
  656.         tft.print(" ");
  657.         tft.setCursor(58,60);
  658.         tft.setTextSize(1);
  659.         tft.print(F("L/"));
  660.         tft.setCursor(58,70);
  661.         tft.setTextSize(1);
  662.         tft.print(F("100"));
  663.        
  664.         tft.drawFastHLine(0, 55, 168, ST7735_GREEN);
  665.        
  666.         tft.setCursor(80,36);
  667.         tft.setTextSize(2.5);
  668.         tft.print(speed, 0);
  669.         tft.print("  ");
  670.         tft.setCursor(125,42);
  671.         tft.setTextSize(1);
  672.         tft.print(F("km/h"));
  673.        
  674.        
  675.         tft.setCursor(80,63);
  676.         tft.setTextSize(2.5);
  677.         tft.print(traveled_distance, 1);
  678.         tft.setCursor(125,70);
  679.         tft.setTextSize(1);
  680.         tft.print(F("km"));
  681.        
  682.     break;
  683.  
  684.     case 1:
  685.        
  686.         tft.setTextColor(ST7735_GREEN , ST7735_BLACK);
  687.         tft.drawBitmap(20, 25,  averagecons, 64, 32, ST7735_GREEN);
  688.         tft.setCursor(54, 10);
  689.         tft.setTextSize(1);
  690.         tft.print(F("LPG"));
  691.         tft.setCursor(74,30);
  692.         tft.setTextSize(1);
  693.         tft.print(F("L/100"));
  694.         tft.setCursor(50, 60);
  695.         tft.setTextSize(3);
  696.         //if(isnan(average_L_100km_Unlead)|| isinf(average_L_100km_Unlead)) tft.println(F("---"));
  697.         //else tft.println(average_L_100km_Unlead, 1);
  698.         if(instant_unlead_consumption > 99.9) tft.print(F("99.9"));
  699.         else tft.print(instant_unlead_consumption  , 2);
  700.     break;
  701.  
  702.     case 2:
  703.         if(inst_disp == true) displaychange = false, inst_disp = false, digitun = 0, posi = 20;
  704.         tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  705.         tft.drawBitmap(60, 25,  speedometer, 32, 32, ST7735_GREEN);
  706.         tft.setCursor(40,56);
  707.         tft.setTextSize(4);
  708.         tft.print(avgspeed1 , 1);
  709.         tft.print("  ");
  710.         //tft.setCursor(98, 54);
  711.         //tft.setTextSize(2);
  712.         //tft.print(F("km"));
  713.         //tft.setCursor(124, 60);
  714.         //tft.setTextSize(3);
  715.         //tft.print(F("/"));
  716.         //tft.setCursor(135, 72);
  717.         //tft.setTextSize(2);
  718.         //tft.print(F("h"));
  719.        
  720.     break;
  721.    
  722.     case 3:  
  723.        
  724.         tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  725.         tft.drawBitmap(31, 25,  avspeed, 64, 32, ST7735_GREEN);
  726.         tft.setCursor(10, 56);
  727.         tft.setTextSize(4);
  728.         tft.print(avg_speed, 0);
  729.         tft.print("  ");
  730.         tft.setCursor(94, 54);
  731.         tft.setTextSize(2);
  732.         tft.print(F("km"));
  733.         tft.setCursor(118, 57);
  734.         tft.setTextSize(3);
  735.         tft.print(F("/"));
  736.         tft.setCursor(130, 68);
  737.         tft.setTextSize(2);
  738.         tft.print(F("h"));
  739.        
  740.     break;
  741.      
  742.     case 4:          
  743.        
  744.         tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  745.         tft.drawBitmap(58, 20,  dist, 32, 32, ST7735_GREEN);
  746.         tft.setCursor(98,38);
  747.         tft.setTextSize(2);
  748.         tft.print(F("km"));
  749.         tft.setCursor(30, 56);
  750.         tft.setTextSize(4);
  751.         tft.print(traveled_distance, 2);
  752.        
  753.     break;
  754.      
  755.     case 5:  
  756.        
  757.         tft.setTextColor(ST7735_RED, ST7735_BLACK);
  758.         tft.drawBitmap(20, 25,  dist_to_LPG, 128, 32, ST7735_RED);
  759.         tft.setCursor(20, 56);
  760.         tft.setTextSize(4);
  761.         if(distance_to_Unleadedstation < 10 ||  isnan(distance_to_Unleadedstation) || isinf(distance_to_Unleadedstation) ) tft.println(F("---"));
  762.         else tft.print(distance_to_Unleadedstation,0);
  763.         tft.setTextSize(2);
  764.         tft.setCursor(120,68);
  765.         tft.print(F("km"));
  766.        
  767.     break;
  768.      
  769.     case 6:
  770.        
  771.         tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
  772.         tft.drawBitmap(30, 30,  leaf, 32, 32, ST7735_WHITE);
  773.         tft.setCursor(70, 32);
  774.         tft.setTextSize(1);
  775.         tft.print(F("Total"));
  776.         tft.setCursor(70, 42);
  777.         tft.setTextSize(2);
  778.         tft.print(F("LPG"));
  779.         tft.setCursor(30, 66);
  780.         tft.setTextSize(2);
  781.         tft.print(used_LPG,1);
  782.         tft.print(F("L"));
  783.        
  784.     break;
  785.  
  786.     case 7:
  787.        
  788.         tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  789.         tft.drawBitmap(45, 25,  FuelTank, 64, 32, ST7735_YELLOW);
  790.         tft.setCursor(30, 60);
  791.         tft.setTextSize(3);
  792.         if (Unleaded_in_tank <= 0 ) tft.print(F("0.0"));
  793.         else tft.print(Unleaded_in_tank,2);
  794.         tft.setTextSize(3);
  795.         tft.setCursor(125,60);
  796.         tft.print(F("L"));
  797.      
  798.     break;
  799.  
  800.     case 8:
  801.  
  802.        
  803.    tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  804.         tft.drawBitmap(96, 30,  Unleaded_fill_nozzle, 32, 32, ST7735_GREEN); //(x,y, name, DX, DY, color)
  805.         tft.setTextSize(1);
  806.         tft.setCursor(20, 40);
  807.         tft.println(F("Total"));
  808.         tft.setTextSize(1);
  809.         tft.setCursor(20, 30);
  810.         tft.println(F("Unleaded"));
  811.         tft.setCursor(40, 63);
  812.         tft.setTextSize(3);
  813.          if(used_Unleaded > 999.9) tft.print(F("999.9"));
  814.         else tft.print(used_Unleaded  , 2);
  815.          
  816.         tft.setTextSize(3);
  817.         tft.setCursor(125,63);
  818.         tft.println(F("L"));
  819.    
  820.     break;
  821.    
  822.     case 9:
  823.        
  824.         tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  825.         tft.drawBitmap(20, 38,  average, 16, 16, ST7735_GREEN);
  826.         tft.drawBitmap(37, 30,  Unleaded_fill_nozzle, 32, 32, ST7735_GREEN);
  827.         tft.setCursor(84,33);
  828.         tft.setTextSize(2);
  829.         tft.println(F("l/100"));
  830.         tft.setCursor(20, 56);
  831.         tft.setTextSize(4);
  832.         //if(isnan(average_L_100km_Unlead)|| isinf(average_L_100km_Unlead)) tft.println(F("---"));
  833.         //else tft.println(average_L_100km_Unlead, 1);
  834.         if(average_L_100km_Unlead > 99.9) tft.print(F("99.9"));
  835.         else tft.print(average_L_100km_Unlead  , 1);
  836.     break;
  837.  
  838.     case 10:
  839.        
  840.        temp1:     if(inst_disp == true) displaychange = false, inst_disp = false;
  841.            
  842.             tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  843.            
  844.             printTemperature();
  845.             tft.drawFastHLine(0, 48, 168, ST7735_GREEN);
  846.             tft.drawFastHLine(0, 49, 168, ST7735_GREEN);
  847.             tft.drawFastHLine(0, 50, 168, ST7735_GREEN);
  848.             tft.setCursor(30, 56);
  849.             tft.setTextSize(3);
  850.             printTime();
  851.           if(sensors.getTempCByIndex(0) < 3.5)
  852.           {
  853.           tft.drawBitmap(0, 3,  snowflake, 16, 16, ST7735_WHITE);
  854.           }
  855.        
  856.       break;
  857. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  858. // the following are secondary displays and activated only in case we want to set the LPG Coef.(case 11) or the Time (case 12)
  859.      
  860.     case 11: // LPG Coef. Setting menu
  861.        
  862.         tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
  863.         tft.setCursor(20,39);
  864.         tft.setTextSize(2);
  865.         tft.println(F("LPG Coef."));
  866.         tft.drawFastHLine(15, 28, 128, ST7735_WHITE);
  867.         tft.drawFastHLine(15, 29, 128, ST7735_WHITE);
  868.        
  869.         tft.setCursor(20,66);
  870.         tft.setTextSize(2);
  871.         tft.println(LPG1);
  872.           tft.setCursor(40,66);
  873.         tft.println(LPG2);
  874.           tft.setCursor(60,66);
  875.         tft.println(LPG3);
  876.           tft.setCursor(80,66);
  877.         tft.println(LPG4);
  878.        
  879.         tft.setCursor(pos,70);
  880.         tft.println(F("_"));
  881.         if (digitalRead(34) == HIGH) counter2 = millis(), displaychange = true; //we must release "button 2" at least once in order to be able to go back to instant LPG consuption
  882.         if ((digitalRead(34) == LOW && millis() - counter2 > 3000 && displaychange == true) || millis() - counter > 10000){
  883.             EEPROM.writeByte(40, LPG1); //stores the new LPG coef.
  884.             EEPROM.writeByte(41, LPG2);
  885.             EEPROM.writeByte(42, LPG3);
  886.             EEPROM.writeByte(43, LPG4);
  887.          LPG_injector_flow = (LPG1 * 1000 + LPG2 * 100 + LPG3 * 10 + LPG4) * 1e-11;
  888.          ignoreRelease = true;
  889.          inst_disp = true;
  890.          lastButtonState2 = LOW;
  891.          tft.fillScreen(ST7735_BLACK);
  892.          menunumber = 0;  
  893.          goto cons1;      
  894.         }
  895.        
  896.     break;
  897.  
  898.     case 12: //RTC set
  899.      
  900.         tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
  901.         tft.setCursor(30,30);
  902.         tft.setTextSize(2);
  903.         tft.print(F("Time Set"));
  904.         tft.drawFastHLine(15, 48, 128, ST7735_WHITE);
  905.         tft.drawFastHLine(15, 49, 128, ST7735_WHITE);
  906.  
  907.         if (timeRead == true){
  908.         DateTime dt = rtc.now();
  909.         h = dt.hour();
  910.         m = dt.minute();
  911.         m1 = dt.minute();
  912.         timeRead = false;
  913.         }
  914.         tft.setCursor(47, 66);
  915.         tft.setTextSize(2);
  916.         char sdt[15];
  917.         sprintf(sdt, "%02d:%02d", h, m);
  918.         tft.print(sdt);
  919.        
  920.        
  921.         if(digitalRead(34) == HIGH) counter2 = millis(), displaychange = true; //we must release the button 2 at least once in order to be able to go back to Temp and Time screen
  922.         if((digitalRead(34) == LOW && millis() - counter2 > 3000 && displaychange == true) || millis() - counter > 59000){
  923.         DateTime dt = rtc.now();
  924.         s = dt.second();
  925.         if (m != m1) s = (((millis() - counter)/1000))%60;
  926.         else s = dt.second(), m = dt.minute();
  927.         rtc.adjust(DateTime(dt.year(), dt.month(), dt.day(), h, m, s));
  928.         inst_disp = true;
  929.         ignoreRelease = true;
  930.         lastButtonState2 = LOW;
  931.         menunumber = 10;
  932.         }
  933.     break;
  934.      
  935.      case 13:  //Unleaded coeficient
  936.        
  937.         tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
  938.         tft.setCursor(15,40);
  939.         tft.setTextSize(2);
  940.         tft.println(F("Unleaded Coef."));
  941.         tft.drawFastHLine(15, 26, 128, ST7735_WHITE);
  942.         tft.drawFastHLine(15, 27, 128, ST7735_WHITE);
  943.         tft.setCursor(20,66);
  944.         tft.setTextSize(2);
  945.  
  946.         tft.println(un1);
  947.           tft.setCursor(40,66);
  948.         tft.println(un2);
  949.           tft.setCursor(60,66);
  950.         tft.println(un3);
  951.           tft.setCursor(80,66);
  952.         tft.println(un4);
  953.         tft.setCursor(posi,70);
  954.         tft.println(F("_"));
  955.         tft.println(F("  "));
  956.         if(digitalRead(34) == HIGH) counter2 = millis(), displaychange = true; //we must release the button 2 at least once in order to be able to go back to Temp and Time screen
  957.         if((digitalRead(34) == LOW && millis() - counter2 > 3000 && displaychange == true) || millis() - counter > 20000){
  958.             EEPROM.writeByte(50, un1); //stores the new LPG coef.
  959.             EEPROM.writeByte(51, un2);
  960.             EEPROM.writeByte(52, un3);
  961.             EEPROM.writeByte(53, un4);
  962.         unleadedFlow = (un1 * 1000 + un2 * 100 + un3 * 10 + un4) * 1e-11; //unleded coeficent
  963.         inst_disp = true;
  964.         ignoreRelease = true;
  965.         lastButtonState2 = LOW;
  966.         tft.fillScreen(ST7735_BLACK);
  967.         menunumber = 2;  
  968.         }
  969.       }
  970.   }
  971.  
  972. ISR(TIMER1_COMPA_vect) //TIMER1 overflow interrupt -- occurs every 1sec --
  973. {
  974.  
  975.     LPG_Consumption();
  976.     LPG_injector_open_duration = 0;
  977.    
  978.     unleadedConsumption();
  979.     unleadinj_Open_Duration = 0;
  980.    
  981.     seconds_passed++;
  982. }
  983.  
  984. void distance()
  985. {
  986.   unsigned long time = millis();
  987.   vss_pulses++;
  988.   traveled_distance += vss_pulse_distance;  
  989.   traveled_distance2 += vss_pulse_distance;
  990.   traveled_distance3 += vss_pulse_distance;
  991.                                             // we calculate 3 times the same thing in order to reset the distance, the average cons. and average speed independently
  992.   unsigned long dt = time - last_speed_calculation_time;                                   
  993.   if (dt >= 1000) {
  994.       instantSpeed(dt);
  995.       last_speed_calculation_time = time;
  996.   }
  997. }
  998.  
  999. void instantSpeed(unsigned int dt)
  1000. {
  1001.   speed = (vss_pulse_distance * vss_pulses * 3600 * 1000 / dt);
  1002.   vss_pulses = 0;
  1003. }
  1004.  
  1005. // The following routine is giving the way to calculate the total time that LPG injector open during the 1sec interval
  1006. void LPG_injector_time()
  1007. {
  1008.   injTime2 = micros();
  1009.     if ((injTime2 - injTime1)<5000 && (injTime2 - injTime1)> 4)
  1010.     {
  1011.     LPG_injector_open_duration = LPG_injector_open_duration + injTime2 - injTime1;
  1012.     }  
  1013.   injTime1 = injTime2;
  1014. }
  1015.  
  1016.  
  1017. void LPG_Consumption()
  1018. {
  1019. if (speed > 2 ) instant_LPG_consumption = (100*((LPG_injector_open_duration * LPG_injector_flow)*3600))/speed;
  1020.                                                                                                        
  1021. else  instant_LPG_consumption = LPG_injector_open_duration * LPG_injector_flow * 3600; // when the car stops calculates the instant consumption in l/h
  1022.  
  1023. used_LPG = used_LPG + (LPG_injector_open_duration * LPG_injector_flow);      
  1024. used_LPG2 = used_LPG2 + (LPG_injector_open_duration * LPG_injector_flow);    
  1025. //LPG_in_tank = LPG_in_tank - (LPG_injector_open_duration * LPG_injector_flow);
  1026. }
  1027.  
  1028. void UnleadedTime() // it is called every time a change occurs at the gasoline injector signal and calculates gasoline injector opening time, during the 1sec interval
  1029.  
  1030.   {
  1031.   if (digitalRead(19) == LOW)
  1032.       {
  1033.         unleadTime1 = micros();
  1034.       }
  1035.   if (digitalRead(19) == HIGH)
  1036.       {
  1037.         unleadTime2 = micros();
  1038.       }
  1039.   if (unleadTime2 > unleadTime1)
  1040.       {if ((unleadTime2 - unleadTime1) > 500 && (unleadTime2 - unleadTime1) < 12000) // some conditions to avoid false readings because of noise
  1041.                                                                                  
  1042.         {
  1043.         unleadinj_Open_Duration = unleadinj_Open_Duration + (unleadTime2 - unleadTime1); //total useconds that the gasoline injector opens throughout 1sec                                                                                
  1044.         }
  1045.       }  
  1046.   }
  1047.  
  1048. void unleadedConsumption()
  1049. {
  1050.   if (speed > 2 ) instant_unlead_consumption = (100*((unleadinj_Open_Duration * unleadedFlow)*3600))/speed;
  1051.                                                                                                        
  1052.   else  instant_unlead_consumption = unleadinj_Open_Duration * unleadedFlow * 3600; // when the car stops calculates the instant consumption in l/h
  1053.  
  1054.  
  1055.   used_Unleaded = used_Unleaded + (unleadinj_Open_Duration * unleadedFlow);  
  1056.   used_Unleaded2 = used_Unleaded2 + (unleadinj_Open_Duration * unleadedFlow);
  1057.   Unleaded_in_tank = Unleaded_in_tank - (unleadinj_Open_Duration * unleadedFlow);
  1058. }
  1059.  
  1060.  
  1061. void ignitionSignal() // this is called everytime the ingintion signal changes -- if the microcontroller is in sleep mode, it will wake up
  1062. {
  1063.     ignition = !ignition;
  1064. }
  1065.  
  1066. void printTime()
  1067. {
  1068.   DateTime dt = rtc.now();
  1069.   char sdt[15];
  1070.   sprintf(sdt, "%02d:%02d", dt.hour(), dt.minute());
  1071.   tft.println(sdt);          
  1072. }
  1073.  
  1074. void printTemperature()
  1075. {
  1076.  
  1077.         // call sensors.requestTemperatures() to issue a global temperature
  1078.  // request to all devices on the bus
  1079. /********************************************************************/
  1080.  
  1081.  sensors.requestTemperatures(); // Send the command to get temperature readings  
  1082.  //Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?  
  1083.  //delay(1000);
  1084.        
  1085.         //if (sensors.getTempCByIndex(0) <0 && sensors.getTempCByIndex(0) > -0.6)
  1086.         //if(sensors.getTempCByIndex(0) >= 9.5 || (sensors.getTempCByIndex(0) <= -0.6 && sensors.getTempCByIndex(0) > -9.6)) postemp = 62; //postemp: the x position of the cursor is depended on how many characters the temp has (1, 2 or 3)
  1087.         //if(sensors.getTempCByIndex(0) < 9.5 && sensors.getTempCByIndex(0) > -0.6) postemp = 80;
  1088.         //if(sensors.getTempCByIndex(0) <= -9.6) postemp = 44;
  1089.        
  1090.         tft.setCursor(90,30);
  1091.         tft.setTextSize(2);
  1092.         tft.println(sensors.getTempCByIndex(0), 0);
  1093.         tft.setCursor(120, 28);
  1094.         tft.setTextSize(1);
  1095.         tft.println(F("o"));
  1096.         tft.setCursor(128, 30);
  1097.         tft.setTextSize(2);
  1098.         tft.println(F("C"));
  1099.  
  1100.         tft.setCursor(20,30);
  1101.         tft.setTextSize(2);
  1102.         tft.println(sensors.getTempCByIndex(1), 0);
  1103.         tft.setCursor(50, 28);
  1104.         tft.setTextSize(1);
  1105.         tft.println(F("o"));
  1106.         tft.setCursor(58, 30);
  1107.         tft.setTextSize(2);
  1108.         tft.println(F("C"));
  1109.    
  1110.  
  1111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement