Basically, when I start-up the Arduino my OLED shows "Welcome" as intended and also shows 'Temperature' as intended but then after a few seconds it loops. Something even stranger is it only loops once and then goes back to normal.
This is my code so far, ignore the incomplete loop part as that is for later:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int tempPin = A0;
int rawValue = 0;
void setup() {
// put your setup code here, to run once:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10,16);
display.println("Welcome");
display.display();
delay(1000);
display.clearDisplay();
display.display();
display.setTextSize(1);
display.setCursor(16, 0);
display.println("Temperature:");
display.display();
}
void loop() {
// put your main code here, to run repeatedly:
rawValue = analogRead(tempPin);
float voltage = rawValue * (5 / 1023.0);
float tempC = (voltage - 0.5) * 100;
}
// add these lines at the end of loop()
display.setCursor(16, 0);
display.print("Temperature:");
display.setCursor(16, 10);
display.print(tempC);
display.display();
delay(500);
display.clearDisplay();