Hi
Im trying to use the unit 8 encoder with M5 Paper. I want to get the LED to change colour with pressing the rotary dial in using getbuttonstatus. I have managed to record the button press however it returns to its previous state without repressing the button. Any advice where Im going wrong?
Here is my code:
#include "UNIT_8ENCODER.h"
#include <M5EPD.h>
UNIT_8ENCODER sensor;
M5EPD_Canvas canvas(&M5.EPD);
int32_t encoder[8] = {0};
uint8_t btn_status[8] = {0};
void show_encoder_value(void) {
for (int i = 0; i < 8; i++) {
btn_status[i] = sensor.getButtonStatus(i);
encoder[i] = sensor.getEncoderValue(i);
}
if (btn_status[i] ==true) {
sensor.setLEDColor(i, 0x00ff00);
}
else {
sensor.setLEDColor(i, 0xff0000);
}
}
}
void setup() {
sensor.begin(&Wire, ENCODER_ADDR, 25, 32, 100000UL);
M5.begin(true,true,true,true,true);
M5.RTC.begin();
M5.EPD.SetRotation(90);
M5.EPD.Clear(true);
canvas.createCanvas(540, 960);
}
void loop() {
// put your main code here, to run repeatedly:
show_encoder_value();
canvas.setTextSize(3);
canvas.drawString(String(encoder[0]), 60, 30);
canvas.drawString(String(encoder[1]), 125, 30);
canvas.drawString(String(encoder[2]), 190, 30);
canvas.drawString(String(encoder[3]), 255, 30);
canvas.drawString(String(encoder[4]), 60, 60);
canvas.drawString(String(encoder[5]), 125, 60);
canvas.drawString(String(encoder[6]), 190, 60);
canvas.drawString(String(encoder[7]), 255, 60);
canvas.drawString(String(btn_status[0]), 60, 130);
canvas.drawString(String(btn_status[1]), 125, 130);
canvas.drawString(String(btn_status[2]), 190, 130);
canvas.drawString(String(btn_status[3]), 255, 130);
canvas.drawString(String(btn_status[4]), 60, 160);
canvas.drawString(String(btn_status[5]), 125, 160);
canvas.drawString(String(btn_status[6]), 190, 160);
canvas.drawString(String(btn_status[7]), 255, 160);
canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
delay(100);
}
Thanks
David