#include "M5Atom.h"

const uint8_t A_letter[5] = {
  0b01110,
  0b10001,
  0b11111,
  0b10001,
  0b10001
};

const CRGB colors[] = {
  CRGB::Red,
  CRGB::Green,
  CRGB::Blue,
  CRGB::Yellow,
  CRGB::Purple,
  CRGB::Cyan,
  CRGB::White
};

const int COLOR_COUNT = sizeof(colors) / sizeof(colors[0]);

int colorIndex = 0;

int getPixelIndex(int x, int y) {
  return (y % 2 == 0)
    ? (y * 5 + x)
    : (y * 5 + (4 - x));
}

void drawA(CRGB color) {
  M5.dis.clear();

  for (int y = 0; y < 5; y++) {
    for (int x = 0; x < 5; x++) {
      if (A_letter[y] & (1 << (4 - x))) {
        int pixelIndex = getPixelIndex(x, y);
        M5.dis.drawpix(pixelIndex, color);
      }
    }
  }
}

CRGB getCurrentColor() {
  return colors[colorIndex];
}

void setup() {
  M5.begin(true, false, true);
  M5.dis.setBrightness(40);

  drawA(getCurrentColor());
}

void loop() {
  M5.update();

  if (M5.Btn.wasPressed()) {
    colorIndex = (colorIndex + 1) % COLOR_COUNT;
    drawA(getCurrentColor());
  }

  delay(50);
}