From 229d4394b201432b5f33a48d36d2d9ad853b1a2a Mon Sep 17 00:00:00 2001 From: Mikhail Grushinskiy Date: Sun, 27 Oct 2024 21:14:15 -0400 Subject: [PATCH] Create bbn_m5atomS3_lite_encoder_unit.ino --- .../bbn_m5atomS3_lite_encoder_unit.ino | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 bbn_m5atomS3_lite_encoder_unit/bbn_m5atomS3_lite_encoder_unit.ino diff --git a/bbn_m5atomS3_lite_encoder_unit/bbn_m5atomS3_lite_encoder_unit.ino b/bbn_m5atomS3_lite_encoder_unit/bbn_m5atomS3_lite_encoder_unit.ino new file mode 100644 index 0000000..4059240 --- /dev/null +++ b/bbn_m5atomS3_lite_encoder_unit/bbn_m5atomS3_lite_encoder_unit.ino @@ -0,0 +1,34 @@ +#include +#include +#include "Unit_Encoder.h" + +Unit_Encoder sensor; +signed short int last_encoder_value = 0; + +void setup() { + auto cfg = M5.config(); + AtomS3.begin(cfg); + Wire.begin(); + Serial.begin(4800); + sensor.begin(&Wire, ENCODER_ADDR, G2, G1, 100000U); +} + +void loop() { + signed short int encoder_value = sensor.getEncoderValue(); + bool btn_status = sensor.getButtonStatus(); + if (last_encoder_value != encoder_value) { + Serial.println(encoder_value); + if (last_encoder_value < encoder_value) { + sensor.setLEDColor(1, 0x00FF00); + } else { + sensor.setLEDColor(2, 0xFF0000); + } + last_encoder_value = encoder_value; + } else { + sensor.setLEDColor(0, 0x0000FF); + } + if (!btn_status) { + sensor.setLEDColor(0, 0xFF00FF); + } + delay(200); +}