#include <Adafruit_BusIO_Register.h> //Näytön vaatima library
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>
#include <Adafruit_GFX.h> //Näytön vaatima library
#include <Adafruit_GrayOLED.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <Adafruit_SSD1306.h> //Näytön vaatima library
#include <splash.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// put your setup code here, to run once:
// The setup function should follow the declaration of any variables at the very
// beginning of the program. It is the first function to run in the program, it's run only
// once, and it's used to set pinMode or initialize serial communication.
// AI:tä ei tarvitse erikseen asettaa. Ainoastaan digitaaliset inputit ja outputit
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("SSD1306 allocation failed");
while(1); //Don't proceed, loop forever
}
//display.display();
//delay(100);
//display.clearDisplay();
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(50, 10);
display.print("start");
display.display();
delay(400);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(5, 0);
display.println("pot value:");
display.setCursor(5, 30);
display.println("analog ip:");
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.print("Analog Value =");
Serial.println(sensorValue);
float voltage = (sensorValue / 1023.0) * 5.0;
Serial.print("Voltage = ");
Serial.print(voltage);
Serial.println(" V");
display.setTextSize(1);
display.setCursor(5, 0);
display.println("pot value:");
display.setCursor(5, 30);
display.println("analog ip:");
display.setCursor(5,15);
display.print(sensorValue);
display.setCursor(5,45);
display.print(voltage);
display.display();
delay(1000);
display.clearDisplay(); // JES OIVALSIN! Uudet numerot piirtyi vanhojen päälle
}