#include "EncoderTool.h" // Thư viện đọc encoder
using namespace EncoderTool;
#include <Bounce2.h>
Encoder encoder;
#include <Servo.h>
#include <ServoSmooth.h>
ServoSmooth servo;//Khai báo đối tượng Servo
#include <Adafruit_GFX.h> // Thư viện điều khiển Oled
#include <Adafruit_SSD1306.h> // Thư viện điều khiển Oled
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 5
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define servoPin 6
static int pos;
unsigned long tmr = 0;
boolean flag;
unsigned long timer1 = 0;
void setup(){
encoder.begin(3, 2);
servo.attach(servoPin);
servo.setSpeed(360);
servo.setAccel(0.05);
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay(); // clearing the display
display.setTextColor(WHITE); //setting the color
display.setTextSize(5); //set the font size
display.setCursor(6,2); //set the cursor coordinates
display.print("PLUS");
display.setTextColor(WHITE); //setting the color
display.setTextSize(1); //set the font size
display.setCursor(0,50); //set the cursor coordinates
display.print("stationery,and beyond");
display.display();
delay(2000);
display.clearDisplay();
}
void loop()
{
servo.tick();
servo.setTargetDeg(pos);
readEncoder();
}
void readEncoder() {
if (encoder.valueChanged()){
pos=encoder.getValue();
}
}