Fully functional code for LÜTR v1.
Dependencies: PM2_Libary Adafruit_GFX BME680
Revision 8:ea7e699a4772, committed 2021-05-04
- Comitter:
- pfammjur
- Date:
- Tue May 04 18:25:29 2021 +0000
- Parent:
- 7:5a1264805a60
- Child:
- 9:efff9b059ea1
- Commit message:
- custom settings for prototype
Changed in this revision
BME680OLED.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/BME680OLED.cpp Sun May 02 20:02:24 2021 +0000 +++ b/BME680OLED.cpp Tue May 04 18:25:29 2021 +0000 @@ -52,10 +52,9 @@ Servo servo_S1(PB_2); int servoPeriod_mus = 20000; //Zeitperiode int servoOutput_mus_S1 = 0; -int servoOutput_mus_S2 = 0; int servo_counter = 0; -int servoMax = 2300, servoMin = 300; -float a = 11.4286, b = -557.142; //Gas -> Rotation +int servoMax = 750, servoMin = 450; //2300: 180 ; 300: 0 +float a = -2.5, b = 1000; //Gas -> Rotation //Methodendeklaration @@ -66,9 +65,10 @@ Timer user_button_timer,mode_button_timer, loop_timer; int Ts_ms = 500; int mode = 1; +int counter = 0; //Buttons -InterruptIn user_button(USER_BUTTON); +InterruptIn user_button(D6); InterruptIn mode_button(D5); void user_button_fall(); void user_button_rise(); @@ -77,8 +77,10 @@ void setup(){ //Setup wird 1 mal durchlaufen loop_timer.start(); + user_button.mode(PullUp); user_button.fall(&user_button_fall); //von 1 auf 0 user_button.rise(&user_button_rise); //von 0 auf 1 + mode_button.mode(PullUp); mode_button.fall(&mode_button_fall); mode_button.rise(&mode_button_rise); thread_sleep_for(1000); //Logo Anzeigen lassen @@ -119,7 +121,7 @@ oled.printf("Luftf.: %.2f %%\r\n",bme680.getHumidity()); oled.printf("Luftdr.: %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.printf("%d",mode); + oled.printf("%d",counter ); oled.display(); }else{ printf("Failed to perform reading :(\n"); @@ -144,15 +146,15 @@ } break; } - - //Servo - float output = a*(bme680.getGasResistance()/1000.0)+b; - if(output>=servoMin){ - servoPos(static_cast<int>(output),250,0); - }else{ - servoPos(servoMin,250,0); + if(counter%10==0){ + //Servo + float output = a*(bme680.getGasResistance()/1000.0)+b; + if(output>=servoMin && output<=servoMax){ + servoPos(static_cast<int>(output),250,0); + }else{ + servoPos(servoMin,250,0); + } } - //LED myled = !myled; @@ -161,6 +163,7 @@ int dT_loop_ms = Ts_ms - T_loop_ms; if(dT_loop_ms>=0 && dT_loop_ms<=Ts_ms)thread_sleep_for(dT_loop_ms); oled.clearDisplay(); + (counter==10000) ? counter=0 : counter++; }else{ oled.clearDisplay(); @@ -172,9 +175,8 @@ //Servo Position 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); + servo_S1.Enable(servoMin, servoPeriod_mus); + servo_S1.SetPosition(pos); thread_sleep_for(wait1); servo_S1.Disable(); thread_sleep_for(wait2); @@ -190,7 +192,7 @@ { int t_button = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); user_button_timer.stop(); - if(t_button > 10) executeMainTask = !executeMainTask; + if(t_button > 30) executeMainTask = !executeMainTask; } //Mode-Buttons void mode_button_fall()