/*
 * Tiny4kOLED - Drivers for SSD1306 controlled dot matrix OLED/PLED 128x32 displays
 *
 * Based on ssd1306xled, re-written and extended by Stephen Denne
 * from 2017-04-25 at https://github.com/datacute/Tiny4kOLED
 *
 */

// Choose your I2C implementation before including Tiny4kOLED.h
// The default is selected is Wire.h

// To use the Wire library:
//#include <Wire.h>

// To use the Adafruit's TinyWireM library:
#include <TinyWireM.h>

// To use the TinyI2C library from https://github.com/technoblogy/tiny-i2c
//#include <TinyI2CMaster.h>

// The blue OLED screen requires a long initialization on power on.
// The code to wait for it to be ready uses 20 bytes of program storage space
// If you are using a white OLED, this can be reclaimed by uncommenting
// the following line (before including Tiny4kOLED.h):
//#define TINY4KOLED_QUICK_BEGIN

#include <Tiny4kOLED.h>

void setup() {
  //SDA = PB0
  //SCL = PB2
  oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);

}

void loop() {
 
  int sensorValue;
  char quality1 = 'E';
  char quality2 = 'x';
  char quality3 = 't';
  char quality4 = 'r';
  sensorValue = analogRead(A2); // PB4
  if(sensorValue<=40) {
      quality1 = 'L';
      quality2 = 'o';
      quality3 = 'w';
      quality4 = ' ';    }
  else if(sensorValue<=100) {
      quality1 = 'M';
      quality2 = 'o';
      quality3 = 'd';
      quality4 = '.';
    }
  else if(sensorValue<=140) {
      quality1 = 'H';
      quality2 = 'i';
      quality3 = 'g';
      quality4 = 'h';
   }
  else if(sensorValue<=200) {
      quality1 = 'V';
      quality2 = 'e';
      quality3 = 'H';
      quality4 = 'i';
    } 
  oled.clear();
  
  oled.setCursor(8, 0);
 
  oled.setFont(FONT8X16P);
  oled.print(F("UV index    IKE"));

  oled.setCursor(20, 11);
  oled.setFontX2(FONT8X16P);
  oled.print(sensorValue/20);
  oled.print(' ');
  oled.print(quality1);
  oled.print(quality2); 
  oled.print(quality3);
  oled.print(quality4); 

  oled.on(); 

  delay(1000);

}

ATTINY8520PU
tiny:PB5
tiny:PB3
tiny:PB4
tiny:GND
tiny:PB0
tiny:PB1
tiny:PB2
tiny:VCC
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA
pot1:GND
pot1:SIG
pot1:VCC