Skip to content

Commit

Permalink
Create bbn_m5atomS3_lite_encoder_unit.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch authored Oct 28, 2024
1 parent d44b082 commit 229d439
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bbn_m5atomS3_lite_encoder_unit/bbn_m5atomS3_lite_encoder_unit.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <M5AtomS3.h>
#include <Wire.h>
#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);
}

0 comments on commit 229d439

Please sign in to comment.