Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #define OLED_RESET 4
- #define MenuButton 2
- Adafruit_SSD1306 display(OLED_RESET);
- RF24 radio(9, 10); //Define radio (CE-PIN,CSN-PIN)
- const byte rxAddr[6] = "00001"; //RX adress (Same as on TX)
- String received_data;
- int taster = 0; //TasterVariable
- int menucounter = 0; //Menüpunktzähler
- int tasterpressed = 0; //Merker ob Taster gedrückt wurde
- int menubez=0; //Merker für die Menübezeichnung, dass sie nur einmal bei Menüpunkt wechsel angezeigt wird
- float timestamp = 0; //Speichert Umschaltzeitpunkt
- float anzeigedauer = 2000; //Anzeigedauer des Menüpunktes
- float boost = 0;
- float umdruck = 0;
- float systemdruck = 0;
- float boostpeak_max = 0;
- float boost1;
- int boost2;
- int boostflag;
- float boostpeak;
- int z = 0;
- char* menupunkte[]={" Boost", " Boost", " Boost", " Info"}; // Namen der Menüpunkten
- void setup()
- {
- pinMode(MenuButton, INPUT);
- Serial.begin(9600);
- display.begin(SSD1306_SWITCHCAPVCC);
- display.setTextColor(WHITE);
- //___________________________________Funk_INI_________________________________________________________
- radio.begin();
- radio.setPALevel(RF24_PA_LOW); // Transmit Power (MAX,HIGH,LOW,MIN)
- radio.setDataRate( RF24_2MBPS ); //Transmit Speeed (250 Kbits)
- radio.openReadingPipe(0, rxAddr);
- radio.startListening();
- //______________________________________Logo_________________________________________________________
- display.display();
- delay(2000);
- display.clearDisplay();
- }
- void loop()
- {
- Serial.println(systemdruck, 4);
- //______________________________________Einlesen von Tatser_____________________________________________
- taster=digitalRead(MenuButton);
- if ( taster == HIGH )
- {
- tasterpressed=1;
- }
- if (taster == LOW && tasterpressed ==1 )
- {
- menucounter++;
- tasterpressed=0;
- menubez = 0;
- if(menucounter == 4)
- {
- menucounter=0;
- }
- }
- //________________________________________Einlesen der Analogwerten___________________________________________
- //________________________________________Funkwert_Empfangen__________________________________________________
- //delay(5);
- radio.startListening();
- if ( radio.available())
- {
- while (radio.available())
- {
- float potV = 0;
- radio.read(&systemdruck, sizeof(systemdruck));
- //Serial.println(systemdruck, 4); //Diagnose
- }
- }
- // systemdruck = analogRead(0);
- umdruck = analogRead(1);
- //_____________________________________________Boost berechnung________________________________________________
- umdruck = (0.743999*umdruck-15.444444)/100;
- boost = systemdruck - umdruck;
- //________________________________________________Boost max___________________________________________________________
- if(boost > boostpeak_max)
- {
- boostpeak_max = boost;
- }
- switch (menucounter)
- {
- //Menüpunk 1________________________________________________________________________________________________
- case 0:
- MENUBEZ(0);
- if(millis() - timestamp > anzeigedauer)
- {
- if(menubez == 1)
- {
- display.clearDisplay();
- TEXT_BAR();
- boost1 = boostpeak - 0.5; //Wert veränderbar bei was für einem ladedruckabfalll er den boost_max ausgeben soll
- if( boost > boost2)
- {
- boostflag = 1;
- }
- if( boost < boost2)
- {
- boostflag = 0;
- boost2 =0;
- }
- if( boost > boost2 )
- {
- boost2 = boost;
- }
- IST_BOOST(); //Ausgabe_von_IST_boost
- if( boost > boostpeak && boostflag==1 )
- {
- boostpeak = boost;
- }
- //_______________________________________Ausgabe_des_boost_max_5x_blinken_500/300ms
- if(boost > -0.2) //Ausgabe wird erst ab einem Ladedruck größer 0,5Bar ausgeben
- {
- if( boost < boost1 )
- {
- for ( z=0 ; z<6 ; z++)
- {
- display.clearDisplay();
- display.setTextSize(3.5);
- display.setCursor(23, 9);
- display.println(boostpeak);
- TEXT_BAR();
- display.display();
- delay(500); //<-------------------Soll durch millis ersetzt werden, das auch beim Blinken des Messwertes durch das Menü geschaltet werden kann.
- display.setTextSize(3.5);
- display.setCursor(23, 9);
- display.clearDisplay();
- TEXT_BAR();
- display.display();
- delay(300); //<-------------------Soll durch millis ersetzt werden....
- }
- boostpeak=0;
- }
- }
- }
- }
- break;
- //Menüpunk 2________________________________________________________________________________________________
- case 1:
- MENUBEZ(1);
- if(millis() - timestamp > anzeigedauer)
- {
- if(menubez == 1)
- {
- display.clearDisplay();
- TEXT_BAR();
- IST_BOOST();
- }
- }
- break;
- //Menüpunk 3________________________________________________________________________________________________
- case 2:
- MENUBEZ(2);
- if(millis() - timestamp > anzeigedauer)
- {
- if(menubez == 1)
- {
- display.clearDisplay();
- TEXT_BAR();
- display.setTextSize(3.5);
- display.setCursor(23,9);
- display.println(boostpeak_max);
- display.display();
- }
- }
- break;
- //Menüpunk 4________________________________________________________________________________________________
- case 3:
- MENUBEZ(3);
- if(millis() - timestamp > anzeigedauer)
- {
- if(menubez == 1)
- {
- display.clearDisplay();
- display.setTextSize(1);
- display.setCursor(0,0);
- display.println("Boost :");
- display.setCursor(109,0);
- display.println("bar");
- display.setCursor(0,8);
- display.println("Systemdruck:");
- display.setCursor(109,8);
- display.println("bar");
- display.setCursor(0,16);
- display.println("Ambinte :");
- display.setCursor(109,16);
- display.println("bar");
- display.setCursor(0,24);
- display.println("Boost max :");
- display.setCursor(109,24);
- display.println("bar");
- if( boost < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
- {
- display.setCursor(74,0);
- display.println(boost);
- }
- if( boost > 0)
- {
- display.setCursor(80,0);
- display.println(boost);
- }
- if( systemdruck < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
- {
- display.setCursor(74,8);
- display.println(systemdruck);
- }
- if( systemdruck > 0)
- {
- display.setCursor(80,8);
- display.println(systemdruck);
- }
- if( umdruck < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
- {
- display.setCursor(74,16);
- display.println(umdruck);
- }
- if( umdruck > 0)
- {
- display.setCursor(80,16);
- display.println(umdruck);
- }
- display.setCursor(80,24);
- display.println(boostpeak_max);
- display.display();
- }
- }
- break;
- }
- }
- //____________________________________________________________UnterProgramme___________________________________
- void MENUBEZ(int x)
- {
- if (menubez == 0)
- {
- display.clearDisplay();
- display.setTextSize(3.5);
- display.setCursor(0,9);
- display.println(menupunkte[menucounter]);
- if ( x == 0)
- {
- display.setTextSize(1.5);
- display.setCursor(108, 8);
- display.println(" ^");
- }
- if ( x == 2)
- {
- display.setTextSize(1.5);
- display.setCursor(108, 8);
- display.println("max");
- }
- display.display();
- menubez=1;
- timestamp = millis();
- }
- }
- void TEXT_BAR()
- {
- display.setTextSize(1.5);
- display.setCursor(108, 23);
- display.println("bar");
- }
- void IST_BOOST()
- {
- if( boost < 0) // verhindert das verrutschen der Anzeige zwecks "-" Zeichen
- {
- display.setTextSize(3.5);
- display.setCursor(5,9);
- display.println(boost);
- display.display();
- }
- if( boost > 0)
- {
- display.setTextSize(3.5);
- display.setCursor(23,9);
- display.println(boost);
- display.display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement