# Module ENCODER SKU:A006
## 描述 **ENCODER** 是一款兼容 FACE 套件的旋钮控制面板.专为旋转编码控制而设计,其内部集成Mega328微处理器,在旋钮的周围嵌入了由12个LED组成的LED灯环. M5Core与ENCODER之间的串行通信协议是I2C(地址:0x5E) ## 产品特性 - RGB Led显示 - I2C 通讯 - 简洁的API接口 - 内置Mega328 - 编码器检测 ## 包含 - 1x M5Stack ENCODER 模块 ## 规格参数
规格 参数
RGB LED x12
净重 27g
毛重 47g
产品尺寸 58.2*54.2*28mm
包装尺寸 95*65*25mm
材质 Plastic(PC)
## EasyLoader >EasyLoader是一个简洁快速的程序烧录器,其内置了一个产品相关的案例程序,通过简单步骤将其烧录至主控,即可进行一系列的功能验证.**(程序烧录前,请根据设备类型安装相应驱动程序. M5Core型主机[请点击此处查看CP210X驱动安装教程](zh_CN/arduino/arduino_development?id=安装串口驱动),M5StickC/V/T/ATOM系列可免驱动使用)**

案例描述:

显示编码器计数和按键状态,左转减少右转增加.

## 管脚映射 **Mega328 ISP**下载接口Pin脚定义 ## 相关链接 - **[ENCODER 固件](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Module/ENCODER/firmware_328p/FacesEncoder328)** ## 功能函数 **控制RGB灯圈** ```clike /* Parameter: led_index: 0 ~ 11 r, g, b: 0 ~ 254 */ void Led(int led_index, int r, int g, int b){ // I2C send data Wire.beginTransmission(Faces_Encoder_I2C_ADDR); Wire.write(led_index); Wire.write(r); Wire.write(g); Wire.write(b); Wire.endTransmission(); } ``` **读取编码器增量** ```clike void get_encoder_increment(void){ int temp_encoder_increment; // I2C read data Wire.requestFrom(Faces_Encoder_I2C_ADDR, 3); if(Wire.available()){ temp_encoder_increment = Wire.read();// get increment button_state = Wire.read();// get button value } if(temp_encoder_increment > 127){//anti-clockwise direction = 1;// flag for encoder direction encoder_increment = 256 - temp_encoder_increment; } else{// clockwise direction = 0; encoder_increment = temp_encoder_increment; } } ``` ## 案例程序 ### 1.Arduino IDE - [点击此处下载Arduino代码](https://github.com/m5stack/M5Stack/tree/master/examples/Face/ENCODER) ### 2.UIFlow