#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <RotaryEncoder.h>
#define PIN 6
#define MATRIX_WEIGHT 15
#define MATRIX_HEIGHT 15
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WEIGHT, MATRIX_HEIGHT, PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
RotaryEncoder encoder_x(A0, A1);
RotaryEncoder encoder_y(A2, A3);
int newPos_x = 0;
int newPos_y = 0;
char buf_x[50];
char buf_y[50];
void setup()
{
Serial.begin(9600);
matrix.begin();
matrix.setBrightness(100);
}
void loop() {
static int pos_x = 0;
static int pos_y = 0;
encoder_x.tick();
encoder_y.tick();
int newPos_x = encoder_x.getPosition();
int newPos_y = encoder_y.getPosition();
matrix.drawPixel(0, 0, matrix.Color(0xff, 0xff, 0x00));
matrix.show();
if(newPos_x != pos_x || newPos_y != pos_y)
{
sprintf(buf_x, "Posição x: ", newPos_x);
Serial.println(newPos_x);
sprintf(buf_y, "Posição y: ", newPos_y);
Serial.println(newPos_y);
matrix.drawPixel(newPos_x, newPos_y, matrix.Color(0xff, 0xff, 0x00));
matrix.show();
pos_x = newPos_x;
pos_y = newPos_y;
}
}