Fick så galet snabb hjälp innan idag så jag provar igen. Återigen säkert lika enkel fråga för er som kan.
Jag har visning av olika värden på min oled.
Jag "togglar" mellan värdena med en knapp. (i denna kod är det bara 1 som är aktiv, dom andra är bara text än så länge)
När jag kör bara temperaturvisningen utan hela växlingskoden fungerar det mycket bra.
Mitt problem är att den inte vill uppdatera temperaturen kontinuerligt. Detta sker bara när jag "togglar" runt ett varv och visar det igen.
Finns det nått bra/lätt sätt att få värdet att uppdateras kontinuerligt?
det gäller funktionen "case1"
Kod: Markera allt
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h><br>#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const byte buttonPin = 8;
int buttonPushCounter = 0; // counter for the number of button presses
boolean buttonState = LOW; // current state of the button
boolean lastButtonState = LOW; // previous state of the button
// lcd constructor made global in scope so the whole program can sse it
void setup()
{
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
pinMode(buttonPin, INPUT);
sensors.begin();
}
void loop()
{
sensors.requestTemperatures();
float T = sensors.getTempCByIndex(0); // let T be temperature in degC from sensor<br>// floating-point number, with a decimal point
String sT = String(T, 1);
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState)
{
if (buttonState == HIGH)
{
// if the current state is HIGH then the button
// went from off to on:
buttonPushCounter++; // add one to counter
delay (100);
display.clearDisplay();
if (buttonPushCounter > 4) // if couter over 3 reset the counter to 1 to show "Jon"
// and not "Hello All"
{
buttonPushCounter = 1;
}
switch (buttonPushCounter) // choose what to display based on buttonPushCounter value
{
case 1:
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Vattentemp: "); // display temperature in deg Celsius
display.setCursor(0,10);
display.setTextSize(3);
display.print(sT);
display.print(" ");
display.cp437(true); // code page 437
display.write(167); // character 167 is degree
display.println("C");
display.display(); // for the changes to make effect
break;
case 2:
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Yttertemp: "); // display temperature in deg Celsius
display.setCursor(0,10);
display.setTextSize(3);
display.print("20.0");
display.print(" ");
display.cp437(true); // code page 437
display.write(167); // character 167 is degree
display.println("C");
display.display(); // for the changes to make effect
break;
case 3:
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Rokgastemp "); // display temperature in deg Celsius
display.setCursor(0,10);
display.setTextSize(3);
display.print("360");
display.print(" ");
display.cp437(true); // code page 437
display.write(167); // character 167 is degree
display.println("C");
display.display(); // for the changes to make effect
break;
case 4:
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Tid sedan rening: "); // display temperature in deg Celsius
display.setCursor(0,10);
display.setTextSize(3);
display.print("32");
display.print(" ");
display.println("min");
display.display(); // for the changes to make effect
break;
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
delay (100);
}
}