Advertisement
heidepower

Untitled

May 2nd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.49 KB | None | 0 0
  1.  
  2. #include <SPI.h>
  3. #include <Wire.h>
  4. #include <Adafruit_GFX.h>
  5. #include <Adafruit_SSD1306.h>
  6. #include <nRF24L01.h>
  7. #include <RF24.h>
  8.  
  9. #define OLED_RESET 4
  10. #define MenuButton 2
  11.  
  12. Adafruit_SSD1306 display(OLED_RESET);
  13.  
  14. RF24 radio(9, 10); //Define radio (CE-PIN,CSN-PIN)
  15. const byte rxAddr[6] = "00001"; //RX adress (Same as on TX)
  16. String received_data;
  17.  
  18.  
  19.  
  20. int taster = 0; //TasterVariable
  21. int menucounter = 0; //Menüpunktzähler
  22. int tasterpressed = 0; //Merker ob Taster gedrückt wurde
  23. int menubez=0; //Merker für die Menübezeichnung, dass sie nur einmal bei Menüpunkt wechsel angezeigt wird
  24. float timestamp = 0; //Speichert Umschaltzeitpunkt
  25. float anzeigedauer = 2000; //Anzeigedauer des Menüpunktes
  26. float boost = 0;
  27. float umdruck = 0;
  28. float systemdruck = 0;
  29. float boostpeak_max = 0;
  30. float boost1;
  31. int boost2;
  32. int boostflag;
  33. float boostpeak;
  34. int z = 0;
  35.  
  36. char* menupunkte[]={" Boost", " Boost", " Boost", " Info"}; // Namen der Menüpunkten
  37.  
  38.  
  39.  
  40.  
  41. void setup()
  42. {
  43. pinMode(MenuButton, INPUT);
  44. Serial.begin(9600);
  45. display.begin(SSD1306_SWITCHCAPVCC);
  46. display.setTextColor(WHITE);
  47.  
  48. //___________________________________Funk_INI_________________________________________________________
  49. radio.begin();
  50. radio.setPALevel(RF24_PA_LOW); // Transmit Power (MAX,HIGH,LOW,MIN)
  51. radio.setDataRate( RF24_2MBPS ); //Transmit Speeed (250 Kbits)
  52. radio.openReadingPipe(0, rxAddr);
  53. radio.startListening();
  54.  
  55. //______________________________________Logo_________________________________________________________
  56. display.display();
  57. delay(2000);
  58. display.clearDisplay();
  59. }
  60.  
  61.  
  62.  
  63.  
  64. void loop()
  65. {
  66.  
  67.  
  68. Serial.println(systemdruck, 4);
  69. //______________________________________Einlesen von Tatser_____________________________________________
  70. taster=digitalRead(MenuButton);
  71.  
  72. if ( taster == HIGH )
  73. {
  74. tasterpressed=1;
  75. }
  76. if (taster == LOW && tasterpressed ==1 )
  77. {
  78. menucounter++;
  79. tasterpressed=0;
  80. menubez = 0;
  81.  
  82. if(menucounter == 4)
  83. {
  84. menucounter=0;
  85.  
  86. }
  87. }
  88.  
  89.  
  90. //________________________________________Einlesen der Analogwerten___________________________________________
  91. //________________________________________Funkwert_Empfangen__________________________________________________
  92. //delay(5);
  93. radio.startListening();
  94. if ( radio.available())
  95. {
  96. while (radio.available())
  97. {
  98. float potV = 0;
  99. radio.read(&systemdruck, sizeof(systemdruck));
  100. //Serial.println(systemdruck, 4); //Diagnose
  101. }
  102. }
  103.  
  104.  
  105.  
  106. // systemdruck = analogRead(0);
  107. umdruck = analogRead(1);
  108. //_____________________________________________Boost berechnung________________________________________________
  109.  
  110. umdruck = (0.743999*umdruck-15.444444)/100;
  111. boost = systemdruck - umdruck;
  112.  
  113.  
  114. //________________________________________________Boost max___________________________________________________________
  115. if(boost > boostpeak_max)
  116. {
  117. boostpeak_max = boost;
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. switch (menucounter)
  127. {
  128.  
  129.  
  130.  
  131.  
  132.  
  133. //Menüpunk 1________________________________________________________________________________________________
  134.  
  135. case 0:
  136. MENUBEZ(0);
  137. if(millis() - timestamp > anzeigedauer)
  138. {
  139. if(menubez == 1)
  140. {
  141. display.clearDisplay();
  142. TEXT_BAR();
  143.  
  144. boost1 = boostpeak - 0.5; //Wert veränderbar bei was für einem ladedruckabfalll er den boost_max ausgeben soll
  145. if( boost > boost2)
  146. {
  147. boostflag = 1;
  148. }
  149. if( boost < boost2)
  150. {
  151. boostflag = 0;
  152. boost2 =0;
  153. }
  154. if( boost > boost2 )
  155. {
  156. boost2 = boost;
  157. }
  158.  
  159. IST_BOOST(); //Ausgabe_von_IST_boost
  160.  
  161. if( boost > boostpeak && boostflag==1 )
  162. {
  163. boostpeak = boost;
  164. }
  165.  
  166.  
  167. //_______________________________________Ausgabe_des_boost_max_5x_blinken_500/300ms
  168. if(boost > -0.2) //Ausgabe wird erst ab einem Ladedruck größer 0,5Bar ausgeben
  169. {
  170. if( boost < boost1 )
  171. {
  172. for ( z=0 ; z<6 ; z++)
  173. {
  174. display.clearDisplay();
  175. display.setTextSize(3.5);
  176. display.setCursor(23, 9);
  177. display.println(boostpeak);
  178. TEXT_BAR();
  179. display.display();
  180. delay(500); //<-------------------Soll durch millis ersetzt werden, das auch beim Blinken des Messwertes durch das Menü geschaltet werden kann.
  181. display.setTextSize(3.5);
  182. display.setCursor(23, 9);
  183. display.clearDisplay();
  184. TEXT_BAR();
  185. display.display();
  186. delay(300); //<-------------------Soll durch millis ersetzt werden....
  187. }
  188. boostpeak=0;
  189. }
  190. }
  191. }
  192. }
  193. break;
  194.  
  195. //Menüpunk 2________________________________________________________________________________________________
  196.  
  197. case 1:
  198. MENUBEZ(1);
  199.  
  200. if(millis() - timestamp > anzeigedauer)
  201. {
  202. if(menubez == 1)
  203. {
  204. display.clearDisplay();
  205. TEXT_BAR();
  206. IST_BOOST();
  207. }
  208. }
  209. break;
  210.  
  211. //Menüpunk 3________________________________________________________________________________________________
  212.  
  213. case 2:
  214. MENUBEZ(2);
  215. if(millis() - timestamp > anzeigedauer)
  216. {
  217. if(menubez == 1)
  218. {
  219. display.clearDisplay();
  220. TEXT_BAR();
  221. display.setTextSize(3.5);
  222. display.setCursor(23,9);
  223. display.println(boostpeak_max);
  224. display.display();
  225. }
  226. }
  227. break;
  228.  
  229. //Menüpunk 4________________________________________________________________________________________________
  230.  
  231. case 3:
  232. MENUBEZ(3);
  233. if(millis() - timestamp > anzeigedauer)
  234. {
  235. if(menubez == 1)
  236. {
  237. display.clearDisplay();
  238. display.setTextSize(1);
  239.  
  240. display.setCursor(0,0);
  241. display.println("Boost :");
  242. display.setCursor(109,0);
  243. display.println("bar");
  244.  
  245. display.setCursor(0,8);
  246. display.println("Systemdruck:");
  247. display.setCursor(109,8);
  248. display.println("bar");
  249.  
  250. display.setCursor(0,16);
  251. display.println("Ambinte :");
  252. display.setCursor(109,16);
  253. display.println("bar");
  254.  
  255. display.setCursor(0,24);
  256. display.println("Boost max :");
  257. display.setCursor(109,24);
  258. display.println("bar");
  259.  
  260. if( boost < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
  261. {
  262. display.setCursor(74,0);
  263. display.println(boost);
  264. }
  265. if( boost > 0)
  266. {
  267. display.setCursor(80,0);
  268. display.println(boost);
  269. }
  270. if( systemdruck < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
  271. {
  272. display.setCursor(74,8);
  273. display.println(systemdruck);
  274. }
  275. if( systemdruck > 0)
  276. {
  277. display.setCursor(80,8);
  278. display.println(systemdruck);
  279. }
  280. if( umdruck < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
  281. {
  282. display.setCursor(74,16);
  283. display.println(umdruck);
  284. }
  285. if( umdruck > 0)
  286. {
  287. display.setCursor(80,16);
  288. display.println(umdruck);
  289. }
  290. display.setCursor(80,24);
  291. display.println(boostpeak_max);
  292.  
  293. display.display();
  294. }
  295. }
  296. break;
  297. }
  298. }
  299. //____________________________________________________________UnterProgramme___________________________________
  300. void MENUBEZ(int x)
  301. {
  302. if (menubez == 0)
  303. {
  304. display.clearDisplay();
  305. display.setTextSize(3.5);
  306. display.setCursor(0,9);
  307. display.println(menupunkte[menucounter]);
  308. if ( x == 0)
  309. {
  310. display.setTextSize(1.5);
  311. display.setCursor(108, 8);
  312. display.println(" ^");
  313. }
  314. if ( x == 2)
  315. {
  316. display.setTextSize(1.5);
  317. display.setCursor(108, 8);
  318. display.println("max");
  319. }
  320. display.display();
  321. menubez=1;
  322. timestamp = millis();
  323. }
  324. }
  325.  
  326.  
  327.  
  328. void TEXT_BAR()
  329. {
  330. display.setTextSize(1.5);
  331. display.setCursor(108, 23);
  332. display.println("bar");
  333. }
  334.  
  335.  
  336.  
  337. void IST_BOOST()
  338. {
  339. if( boost < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
  340. {
  341. display.setTextSize(3.5);
  342. display.setCursor(5,9);
  343. display.println(boost);
  344. display.display();
  345. }
  346. if( boost > 0)
  347. {
  348. display.setTextSize(3.5);
  349. display.setCursor(23,9);
  350. display.println(boost);
  351. display.display();
  352. }
  353. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement