arduino 读取EC11编码器

2023-11-08 02:40
文章标签 读取 arduino 编码器 ec11

本文主要是介绍arduino 读取EC11编码器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

使用github上的库

实物图

引脚接线

EC11模块引脚

arduino UNO引脚

+

VCC

GND

GND

CLK

2 (3)

DT

3 (2)

github演示代码

  文件存放

//
// Example for EC11 class (Rotary Encoder Helper).
// Copyright (C) 2016, Aleh Dzenisiuk. 
// http://github.com/aleh/ec11
//#include "EC11.hpp"//
// Here we assume that the pins A and B of a EC-11 rotary encoder are connected to pins 2 and 3 of the Arduino Uno
// board and the pin C is connected to the ground.
//EC11 encoder;// Defined as 0 to see how polling-style pin checks behave.
#define DEMO_INTERRUPTS 0 // 0:查询方式读取引脚  1:中断方式读取#if DEMO_INTERRUPTS//
// Interrupt-based example. This is recommended, but it means only pins 2 and 3 can be used with Uno.
//const int encoderPinA = 2;
const int encoderPinB = 3;void pinDidChange() {encoder.checkPins(digitalRead(encoderPinA), digitalRead(encoderPinB));
}void prepare() {attachInterrupt(0, pinDidChange, CHANGE);attachInterrupt(1, pinDidChange, CHANGE);
}#else//
// Polling allows to use the encoder with any digital input pin.
//const int encoderPinA = 2;
const int encoderPinB = 3;void prepare() {
}#endif // #if DEMO_INTERRUPTSvoid setup() {Serial.begin(9600);Serial.println("EC11 Test");// We can use internal pull-up with the encoder pins, assuming pin C is simply grounded.pinMode(encoderPinA, INPUT_PULLUP);pinMode(encoderPinB, INPUT_PULLUP);prepare();
}static int value = 0;void loop() {EC11Event e;if (encoder.read(&e)) {// OK, got an event waiting to be handled.if (e.type == EC11Event::StepCW) {value += e.count;} else {value -= e.count;}Serial.println(value);}#if DEMO_INTERRUPTS// Wait quite some time to demonstrate that we can check for events fairly infrequently and still not miss them.delay(200);#else// With polling-style pin checking we can still read infrequently, but we need to poll the pins often enough.for (int i = 0; i < 200; i++) {encoder.checkPins(digitalRead(encoderPinA), digitalRead(encoderPinB));delay(1);}#endif
}

 串口数据接收

这篇关于arduino 读取EC11编码器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/367455

相关文章

使用Java读取本地文件并转换为MultipartFile对象的方法

《使用Java读取本地文件并转换为MultipartFile对象的方法》在许多JavaWeb应用中,我们经常会遇到将本地文件上传至服务器或其他系统的需求,在这种场景下,MultipartFile对象非... 目录1. 基本需求2. 自定义 MultipartFile 类3. 实现代码4. 代码解析5. 自定

MySQL 数据库表操作完全指南:创建、读取、更新与删除实战

《MySQL数据库表操作完全指南:创建、读取、更新与删除实战》本文系统讲解MySQL表的增删查改(CURD)操作,涵盖创建、更新、查询、删除及插入查询结果,也是贯穿各类项目开发全流程的基础数据交互原... 目录mysql系列前言一、Create(创建)并插入数据1.1 单行数据 + 全列插入1.2 多行数据

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

解决pandas无法读取csv文件数据的问题

《解决pandas无法读取csv文件数据的问题》本文讲述作者用Pandas读取CSV文件时因参数设置不当导致数据错位,通过调整delimiter和on_bad_lines参数最终解决问题,并强调正确参... 目录一、前言二、问题复现1. 问题2. 通过 on_bad_lines=‘warn’ 跳过异常数据3

Python使用openpyxl读取Excel的操作详解

《Python使用openpyxl读取Excel的操作详解》本文介绍了使用Python的openpyxl库进行Excel文件的创建、读写、数据操作、工作簿与工作表管理,包括创建工作簿、加载工作簿、操作... 目录1 概述1.1 图示1.2 安装第三方库2 工作簿 workbook2.1 创建:Workboo

Java中读取YAML文件配置信息常见问题及解决方法

《Java中读取YAML文件配置信息常见问题及解决方法》:本文主要介绍Java中读取YAML文件配置信息常见问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 目录1 使用Spring Boot的@ConfigurationProperties2. 使用@Valu

SpringBoot读取ZooKeeper(ZK)属性的方法实现

《SpringBoot读取ZooKeeper(ZK)属性的方法实现》本文主要介绍了SpringBoot读取ZooKeeper(ZK)属性的方法实现,强调使用@ConfigurationProperti... 目录1. 在配置文件中定义 ZK 属性application.propertiesapplicati

Python中文件读取操作漏洞深度解析与防护指南

《Python中文件读取操作漏洞深度解析与防护指南》在Web应用开发中,文件操作是最基础也最危险的功能之一,这篇文章将全面剖析Python环境中常见的文件读取漏洞类型,成因及防护方案,感兴趣的小伙伴可... 目录引言一、静态资源处理中的路径穿越漏洞1.1 典型漏洞场景1.2 os.path.join()的陷

如何使用 Python 读取 Excel 数据

《如何使用Python读取Excel数据》:本文主要介绍使用Python读取Excel数据的详细教程,通过pandas和openpyxl,你可以轻松读取Excel文件,并进行各种数据处理操... 目录使用 python 读取 Excel 数据的详细教程1. 安装必要的依赖2. 读取 Excel 文件3. 读

Spring Boot读取配置文件的五种方式小结

《SpringBoot读取配置文件的五种方式小结》SpringBoot提供了灵活多样的方式来读取配置文件,这篇文章为大家介绍了5种常见的读取方式,文中的示例代码简洁易懂,大家可以根据自己的需要进... 目录1. 配置文件位置与加载顺序2. 读取配置文件的方式汇总方式一:使用 @Value 注解读取配置方式二