Fully functional code for LÜTR v1.
Dependencies: PM2_Libary Adafruit_GFX BME680
Revision 6:bb38624001e8, committed 2021-04-26
- Comitter:
- pfammjur
- Date:
- Mon Apr 26 19:21:44 2021 +0000
- Parent:
- 5:ae69059b2799
- Child:
- 7:5a1264805a60
- Commit message:
- Servo + Layout
Changed in this revision
BME680OLED.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/BME680OLED.cpp Mon Apr 26 09:51:27 2021 +0000 +++ b/BME680OLED.cpp Mon Apr 26 19:21:44 2021 +0000 @@ -54,12 +54,12 @@ int servoOutput_mus_S1 = 0; int servoOutput_mus_S2 = 0; int servo_counter = 0; -//int loops_per_second = static_cast<int>(ceilf(1.0f/(0.001f*(float)Ts_ms))); -int servoMax = 2000, servoMin = 0; +int servoMax = 2300, servoMin = 300; +float a = 11.4286, b = -557.142; //Gas -> Rotation //Methodendeklaration -void servoPos(int pos,int wait); +void servoPos(int pos,int wait1, int wait2); @@ -67,16 +67,13 @@ thread_sleep_for(1000); //Logo Anzeigen lassen pc.set_baud(9600); //baudrate set_time(1619033310); // Set RTC time to Wed, 21. April 2021 19:28:30 https://www.epochconverter.com/ - oled.clearDisplay(); - oled.drawPixel (10, 10,WHITE); - oled.display(); thread_sleep_for(1000); oled.clearDisplay(); if (!bme680.begin()) { //begin() startet Sensor: Vorheizen usw... oled.printf("BME680 Begin failed \r\n"); //Fehlermeldung } - servoPos(2000,1000); - servoPos(0,1000); + servoPos(servoMax,1000,1000); + servoPos(servoMin,1000,1000); } @@ -85,6 +82,8 @@ setup(); //uint16_t i=0; + + while(true) { oled.setTextCursor(0,0); @@ -98,28 +97,35 @@ //BME680 oled.setTextCursor(0,15); if (bme680.performReading()) { //Sensor auslesen - oled.printf("Temperatur: %.2f C \r\n",bme680.getTemperature()); - oled.printf("Humidity: %.2f %% \r\n",bme680.getHumidity()); - oled.printf("Pressure: %d hPa \r\n",static_cast<int>(bme680.getPressure()/100)); - oled.printf("VOC: %d KOhms \r\n",(static_cast<int>(bme680.getGasResistance()/1000.0))); + oled.printf("Temperatur: %.2f C\r\n",bme680.getTemperature()); + oled.printf("Luftf.: %.2f %%\r\n",bme680.getHumidity()); + oled.printf("Luftfr.: %d hPa\r\n",static_cast<int>(bme680.getPressure()/100)); + oled.printf("VOC: %d kOhm\r\n",(static_cast<int>(bme680.getGasResistance()/1000.0))); oled.display(); - }else{ printf("Failed to perform reading :(\n"); - } + } + + //Servo + float output = a*(bme680.getGasResistance()/1000.0)+b; + if(output>=servoMin){ + servoPos(static_cast<int>(output),500,0); + }else{ + servoPos(servoMin,500,0); + } myled = !myled; - thread_sleep_for(1000); + thread_sleep_for(500); oled.clearDisplay(); } } -void servoPos(int pos,int wait){ +void servoPos(int pos,int wait1,int wait2){ servo_S1.Enable(servoOutput_mus_S1, servoPeriod_mus); servoOutput_mus_S1 = pos; servo_S1.SetPosition(servoOutput_mus_S1); - thread_sleep_for(1000); + thread_sleep_for(wait1); servo_S1.Disable(); - thread_sleep_for(wait); + thread_sleep_for(wait2); } \ No newline at end of file