#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 oled(SCREEN_WIDTH,SCREEN_HEIGHT, &Wire, -1);
float floatmap(float x,float in_min,float in_max,float out_min,float out_max){
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
const int led1 = 13;
const int led2 = 12;
const int led3 = 14;
const int button = 27;
int buttonState = HIGH;
int lastButtonState = HIGH;
bool tekanbutton = false;
const int potpin = 35;
int potValue = 0;
void setup(){
Serial.begin(9600);
analogSetAttenuation(ADC_11db);
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)){
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000);
oled.clearDisplay();
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);
pinMode (button, INPUT_PULLUP);
}
void loop(){
buttonState = digitalRead(button);
if (buttonState== LOW && lastButtonState == HIGH){
tekanbutton=!tekanbutton;
}
if (tekanbutton){
digitalWrite(13, HIGH);
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0, 10);
oled.println("Led 1 nyala");
oled.display();
}
potValue = analogRead(35);
if (potValue > 220) {
digitalWrite(led2, HIGH);
oled.setCursor(0, 30);
oled.println("Led 2 nyala");
oled.display();
} else {
digitalWrite(led2, LOW);
}
if (potValue > 330) {
digitalWrite(led3, HIGH);
oled.setCursor(0, 50);
oled.println("Led 3 nyala");
oled.display();
} else {
digitalWrite(led3, LOW);
}
buttonState=lastButtonState;
delay(1000);
}