简体   繁体   English

绝对编码器十六进制输入

[英]Absolute Encoder hexadecimal input

Question: How do I receive input from a absolute encoder that makes it output in hexadecimal/grey code into a Arduino? 问题:如何从绝对编码器接收输入,使其以十六进制/灰色代码输出到Arduino? do I use a digitalRead or analogRead command? 我用一个digitalReadanalogRead命令? I could not find example code/projects with a absolute encoder online. 我找不到在线绝对编码器的示例代码/项目。

Overall Objective: I want to use a absolute encoder as a knob for a project. 总体目标:我想使用绝对编码器作为项目的旋钮。 The idea is that the encoder will output its position as a state to be used in a case statement. 这个想法是编码器将输出其位置作为要在case语句中使用的状态。 Ie: 即:

case1: analogRead(absEncdr == 00) arduino enters idle routine 情况1: analogRead(absEncdr == 00) arduino进入空闲例程

case2: analogRead(absEncdr == 11) arduino enters button routine case2: analogRead(absEncdr == 11) arduino进入按钮例程

etc 等等

details: Abs encoder type: 25LB22-G encoder datasheet is here . 详细信息:Abs编码器类型:25LB22-G编码器数据表在此处

I'm using the hexidecimal/ grey code 4-Bit Binary Code Hexadecimal-16 Position encoder version 我正在使用十六进制/格雷码4位二进制码十六进制16位置编码器版本

Basically, I'm not sure how to read in this abs encoder into my Arduino. 基本上,我不确定如何将此Abs编码器读入Arduino。

To read that you will need four digital pins. 要阅读该书,您将需要四个数字引脚。 You can read the four pins and bit-shift those values into one byte that you can compare to the table in the data-sheet. 您可以读取这四个引脚,并将这些值移位到一个字节,然后将其与数据表中的表进行比较。

byte position = (digitalRead(pin8) << 3) | (digitalRead(pin4) << 2) | (digitalRead(pin2) << 1) | digitalRead(pin1);

Assuming that the pins are named as they are in that truth table in the datasheet. 假设引脚的名称与数据表中真值表中的名称相同。

We are using the OR operator | 我们正在使用OR运算符| to put them together into the same byte. 将它们放到同一个字节中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM