Teensy 4.x Quadratur-Encoder-Minimalbeispiel in PlatformIO/Arduino
English
Deutsch
Dieses Beispiel verwendet PlatformIO und die Teensy-4.x-Quad-Encoder-Library, um einen Hardware-Quadratur-Encoder auf den Pins 0 und 1 zu implementieren. Beachten, dass der Teensy zerstört wird, wenn 5V-Encoder-Signale verwendet werden. Es können nur 3,3V-Signale verwendet werden!
main.cpp
#include <Arduino.h>
#include <QuadEncoder.h>
QuadEncoder encoder(1, 0, 1, 0);
void setup() {
Serial.begin(115200);
encoder.setInitConfig();
encoder.init();
}
void loop() {
int32_t position = encoder.read();
// Position in mm berechnen und ausgeben
constexpr float mm_per_count = 0.0012;
float mm = position * mm_per_count;
Serial.printf("Position: %+3.4f (count %ld)\\r\\n", mm, position);
// Alle 50ms ausgeben
delay(50);
}platformio.ini
[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
monitor_speed = 115200
lib_deps =
git+https://github.com/mjs513/Teensy-4.x-Quad-Encoder-LibraryCheck out similar posts by category:
C/C++, Electronics, Embedded, PlatformIO, Teensy
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow