// https://forum.arduino.cc/t/snake-game-on-8-8-leds-not-fully-working/1176943
// https://wokwi.com/projects/378380415031789569

# include <FastLED.h>

# define DATA_PIN 2        // Broche de données du carré de LED
# define NUM_LEDS 64       // Nombre de LEDs (8x8)

CRGB leds[NUM_LEDS];

void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  leds[1] = CRGB(255, 0, 0);
  leds[2] = CRGB(0, 255, 0);
  leds[3] = CRGB(0, 0, 255);
  FastLED.show();
  delay(777);
}

void loop()
{ 
  int number = random(10);
  int x = random(6);
  int y = random(4);

  fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0));
  drawN(number, x, y);
  FastLED.show();

  delay(777);
}

unsigned char font[10][3] = {
/*0*/ {0b11111, 0b10001, 0b11111,},
/*1*/ {0b00000, 0b11111, 0b00000,},
/*2*/ {0b11101, 0b10101, 0b10111,},
/*3*/ {0b10101, 0b10101, 0b11111,},
/*4*/ {0b00111, 0b00100, 0b11111,},
/*5*/ {0b10111, 0b10101, 0b11101,},
/*6*/ {0b11111, 0b10101, 0b11101,},
/*7*/ {0b00001, 0b00001, 0b11111,},
/*8*/ {0b11111, 0b10101, 0b11111,},
/*9*/ {0b10111, 0b10101, 0b11111,},
};

void drawN(int N, int X, int Y)
{
  Y <<= 3;

  for (unsigned char colm = 0; colm < 3; colm++, X++) {
    unsigned char yT = Y;
    unsigned char theBits = font[N][colm];
    unsigned char mask = 0x1;

    for (unsigned char row = 0; row < 5; row++) {
      leds[yT + X] = (mask & theBits) ? CRGB(255, 42, 102) : CRGB(0, 0, 0);
      mask <<= 1;
      yT += 8; 
    }
  }
}

/* dev junk
//for (; ;)
 {
  for (unsigned char ii = 0; ii < 10; ii++) {


    fill_solid( leds, NUM_LEDS, CRGB(200, 255, 240));

//    FastLED.clear();
Serial.print("draw "); Serial.println(ii);
    drawN(ii, 1, 3);
    FastLED.show();

   delay(377);
  }
}
*/