Hoi,
Vanaf regel 75 een aantal if else ..
De String "flapDisplay" blijft echter "0" na de laatse else. (regel 99)
Iets gaat hier fout maar ik staar me blind en vind het niet.
Hulp wordt zeer op prijs gesteld.
Dank
// ******************************************** OLED Display ********************************************
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send ACK
// ********************************************** BME280 ************************************************
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define Sealevel_HPA (1013.25) // Set sealevel
Adafruit_BME280 bme; // I2C
unsigned long delayTime;
// ******************************************* FLAPS Sensor ********************************************
int AGL = 0; // Set initial heigth
int QNH = 0; // Set initial QNH
int sensorPin = A0; // select the input pin for the flaps potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int tol = 5; // set tolerance flaps slider
// ****************************************** Rotary Encoder *******************************************
#define inputCLK 8 // Set input pin CLK
#define inputDT 9 // Set input pin DT
int pinwaarde = 0;
int var = 0; //tijdelijk
int mode = 0;
int flap = 0;
int flapDisplay = 0;
int counter = 0; // Initial encoder count
float currentStateCLK; // Initial CLK state
float previousStateCLK; // Previous CLK state
String encdir = "";
// ****************************************** General Setup ********************************************
void setup() {
int gearPin = 5;
int buzzerPin = 6;
// Rotary encoder setup
pinMode (inputCLK, INPUT); // Set encoder pins as inputs
pinMode (inputDT, INPUT);
pinMode (7, INPUT); // Set input pin encoder switch
pinMode (buzzerPin, OUTPUT); // Buzzer pin
pinMode (gearPin, INPUT); // Gear down switch
Serial.begin(9600); // Start serial port
unsigned status;
status = bme.begin();
}
void loop() {
mode = 0;
delay(1000);
// ******************************************* Read value string potmeter ****************************
sensorValue = analogRead(sensorPin); // Read value flaps string potmeter
if (sensorValue > 100 - tol && sensorValue < 150 + tol) {
String flapDisplay = String ("1"); // Flaps 1
}
else if (sensorValue > 200 - tol && sensorValue < 250 + tol) {
String flapDisplay = String ("2"); // Flaps 2
}
else if (sensorValue > 250 - tol && sensorValue < 275 + tol) {
String flapDisplay = String ("2.5"); // Flaps 2.5
}
else if (sensorValue > 300 - tol && sensorValue < 350 + tol) {
String flapDisplay = String ("3"); // Flaps 3
}
else if (sensorValue > 400 - tol && sensorValue < 450 + tol) {
String flapDisplay = String ("4"); // Flaps 4
}
else if (sensorValue > 500 - tol && sensorValue < 550 + tol) {
String flapDisplay = String ("L1"); // Flaps L1
}
else if (sensorValue > 600 - tol && sensorValue < 650 + tol) {
String flapDisplay = String ("L2"); // Flaps L2
}
else {
String flapDisplay = String ("--"); // Flaps --
}
Serial.println(flapDisplay);
pinwaarde = digitalRead(7);
if (pinwaarde == LOW) {
setElevation();
}
// Print QNH
Serial.print("QNH = ");
Serial.print(int(bme.readPressure() / 100.0F));
Serial.print(" hPa ");
QNH = (int(bme.readPressure() / 100.0F));
// Print AGL
AGL = (bme.readAltitude(Sealevel_HPA));
Serial.print("AGL = ");
Serial.print (AGL + counter);
Serial.println(" m");
if ((AGL + counter < 150) && (digitalRead(5) == HIGH)) { // Set Landing gear warning altitude and determine if gear is down
digitalWrite(6, HIGH);
}
else if (AGL + counter >= 150) {
digitalWrite(6, LOW);
}
// ********************************** Draw data *******************************************
u8g.firstPage();
do {
draw();
} while ( u8g.nextPage() );
}
void draw(void) {
//u8g.setRot180(); // Rotate display 180 degrees
u8g.setFont(u8g_font_profont15);
u8g.drawStr( 85, 10, "Elev");
u8g.setFont(u8g_font_helvR12);
u8g.setPrintPos(85, 25);
u8g.print(AGL + counter);
u8g.setFont(u8g_font_profont15);
u8g.drawStr( 85, 45, "QNH");
u8g.setFont(u8g_font_helvR12);
u8g.setPrintPos(85, 60);
u8g.print(QNH);
u8g.setFont(u8g_font_6x10);
u8g.drawStr(5, 7, "flaps");
u8g.setFont(u8g_font_fub49n);
u8g.setPrintPos(1, 63);
u8g.print(flapDisplay);
}
// ********************************* Subroutine AGL setting ******************************************
void setElevation() { // Set Elevation
var = 0;
while (var < 1) {
pinwaarde = digitalRead(7); // Read pinvalue ecncoder switch
if (pinwaarde == LOW)
{
mode++;
delay(1000);
if (mode == 3) // Long press value encoder switch for break out of loop
break; // Return to main
}
currentStateCLK = digitalRead(inputCLK); inputCLK; // Read the current state of inputCLK
if (currentStateCLK != previousStateCLK) {
if (digitalRead(inputDT) != currentStateCLK) {
counter --;
encdir = "CCW";
} else {
// Encoder is rotating clockwise
counter ++;
encdir = "CW";
}
AGL = (bme.readAltitude(Sealevel_HPA));
Serial.print("AGL = ");
Serial.print (AGL + counter); // Print AGL modified
Serial.println(" m");
previousStateCLK = currentStateCLK; // Update previousStateCLK with the current state
}
}
}