I want to see the progress distance with the rotation of the Rotary Encoder. I will connect the encoder to a coil with a diameter of 10cm. I want it to read the rotation speed of the coil and write it to the screen instantly in meters/minute. But no matter what I did, it didn't work correctly. I give the code below. What should I do? Can you help me?
#include <UTFT.h>
#include <TFT.h>
#include <RotaryEncoder.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
#define PIN_IN1 A2
#define PIN_IN2 A3
#define IMPULSES_PER_ROTATION 360 // Bir turda kaç impuls olduğunu buraya girin
#define DISTANCE_PER_IMPULSE 0.02777777 // Her impulsun aldığı mesafeyi buraya girin (örneğin, 0.02777777 cm)
RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::TWO03);
unsigned long lastMillis = 0; // Son hesaplamanın yapıldığı zamanı takip etmek için kullanılır
int lastPos = 0; // Son pozisyonu saklar
UTFT myGLCD(CTE32HR, 38, 39, 40, 41, true);
void setup() {
myGLCD.InitLCD();
myGLCD.setFont(BigFont);
Serial.begin(9600);
while (!Serial);
Serial.println("RotaryEncoder kütüphanesi testi.");
}
void loop() {
myGLCD.clrScr();
// Sol taraftan hizalı metinleri yazdır
myGLCD.setColor(255, 255, 255);
myGLCD.print("1. KAT Hz (M/Dak):", 10, 30);
myGLCD.print("2. KAT Hz (M/Dak):", 10, 70);
myGLCD.print("3. KAT Hz (M/Dak):", 10, 110);
// Burada encoder değerini okuyun (örnek olarak rastgele bir değer ekledim)
encoder.tick();
int newPos = encoder.getPosition();
unsigned long currentMillis = millis();
// Encoder değerini ekranda görüntüle
if (currentMillis - lastMillis >= 10) {
float metersPerMinute = ((newPos - lastPos) * (31.416 / 500)) * 60; // Metre/Dakika cinsinden hızı hesapla
Serial.print("İlerleme Hızı (metre/dakika): ");
Serial.println(metersPerMinute);
lastMillis = currentMillis;
lastPos = newPos;
}
myGLCD.setColor(255, 255, 255);
myGLCD.printNumI(newPos, 320, 30);
myGLCD.printNumI(newPos, 320, 70);
myGLCD.printNumI(newPos, 320, 110);
//delay(100); // Ekranın hızlıca güncellenmesini engellemek için bir gecikme ekledik
// loop fonksiyonun sonu
}