/***
by Fajar Himawan
https://ayojurnalku.blogspot.com
***/
#include <Stepper.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int SwitchPIN = 7;
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
Serial.begin(115200);
myStepper.setSpeed(1);
pinMode( SwitchPIN, INPUT);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(500);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, -10, 99); // scale it to use it with the servo (value between 0 and 180)
//myStepper.step(val);
// sets the servo position according to the scaled value
delay(15);
// clear display
display.clearDisplay();
// display temperature
display.setTextSize(1);
display.setCursor(0,0);
display.print("Suhu: ");
//display.setTextSize(2);
display.setCursor(0,10);
display.print(val);
display.print(" ");
display.setTextSize(1);
//display.cp437(true);
//display.write(167);
//display.setTextSize(2);
//display.print("C");
// display humidity
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Kelembaban: ");
//display.setTextSize(2);
//display.setCursor(0, 45);
//display.print(h);
//display.print(" %");
display.display();
}