#//include<Wire.h>
#include<Adafruit_GFX.h>
#include<Adafruit_SSD1306.h>
//oled inisialisasi
const int lebar=128;
const int tinggi=64;
const int reset=4;
Adafruit_SSD1306 oled(lebar,tinggi,&Wire,reset);
//inisialisasi sensor
int sensorPin = 2;
volatile long pulse;
unsigned long lastTime;
float flowrate;
void setup() {
//setup pin input sensor
pinMode(sensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(sensorPin), increase, RISING);
//setup oled
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
}
void loop()
{
flowrate = pulse / 6.6;
{
if (millis() - lastTime > 1000)
pulse = 0;
lastTime = millis();
}
oled.clearDisplay();
oled.setTextSize(1.5); //ukuran test nya
oled.setTextColor(WHITE); //kecerahan nya
oled.setCursor(2,15); //baris dan kolom mulainya ygdibawah (flowrate)
oled.println("Q =");
oled.setCursor(30,15); //baris dan kolom mulainya ygdibawah (Volume)
oled.println(flowrate);
oled.setCursor(65,15); //baris dan kolom mulainya ygdibawah (l/min)
oled.println("l/Min");
oled.display();
}
void increase() {
pulse++;
}