#include "LedControl.h"
#include "FONT_console_4x7.h"
LedControl lc = LedControl(4, 15, 2, 4);  // data, clock, CS(load),  number of devices   (ESP32)


void writeDigitPairDirect(  uint8_t digLeft, uint8_t digRight, uint8_t address ) {
  // write pair of digits to the addressed 8x8 led matrix
  uint8_t matrix[8] = {0} ;
  // uint8_t matrix2[8] = {0} ;

  if ( digLeft > 9 ) digLeft = 10 ;
  if ( digRight > 9 ) digRight = 10 ;

  for ( uint8_t i = 0; i < 7 ; i++ ) {
    matrix[ i + 1] = ( FONT_console_4x7[ digRight * 7 + i ] >> 4 )
                  | ( FONT_console_4x7[ digLeft * 7 + i ] ) ;
  }

  	for ( uint8_t i = 0; i < 8 ; i++ ) {
      uint8_t tmp = 0 ;
      for ( uint8_t j = 0; j < 8 ; j++ ) bitWrite( tmp, 7 - j, bitRead( matrix[i] , j)) ;
			lc.setRow( address , i , tmp ) ;    
		}
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  int devices = lc.getDeviceCount();
  for (int address = 0; address < devices; address++) {
    /*The MAX72XX is in power-saving mode on startup*/
    lc.shutdown(address, false);
    /* Set the brightness to a medium values */
    lc.setIntensity(address, 8);
    /* and clear the display */
    lc.clearDisplay(address);
  }

  writeDigitPairDirect(5, 4, 0) ;
  writeDigitPairDirect(10, 2, 1) ;
  //writeDigitPairDirect(3, 4, 2) ;
  //writeDigitPairDirect(1, 2, 3) ;

 
  uint8_t matrix1[ 8 ] = {0} ;
		matrix1[ 7 ] = 3 ;
		matrix1[ 6 ] = 7 ;
		matrix1[ 5 ] = 0xF ;
		matrix1[ 4 ] = 0 ;
		matrix1[ 3 ] = 0 ;
		matrix1[ 2 ] = 0 ;
		matrix1[ 1 ] = 0 ;
		matrix1[ 0 ] = 0 ;

		for ( uint8_t i = 0; i < 8 ; i++ ) {
      uint8_t tmp = 0 ;
      for ( uint8_t j = 0; j < 8 ; j++ ) bitWrite( tmp, 7 - j, bitRead( matrix1[i] , j)) ;
			lc.setRow( 2, 7-i , tmp ) ;    
		}
   
 /*
 uint8_t matrix2[ 8 ] = {0} ;
		matrix2[ 7 ] = 1 ;
		matrix2[ 6 ] = 3 ;
		matrix2[ 5 ] = 7 ;
		matrix2[ 4 ] = 0xF ;
		matrix2[ 3 ] = 0x1F ;
		matrix2[ 2 ] = 0x3F ;
		matrix2[ 1 ] = 0x7F ;
		matrix2[ 0 ] = 0xFF ;

    rotate_flip( matrix2 ) ;
		for ( uint8_t i = 0; i < 8 ; i++ ) {
			//lc.setColumn( 3, i , matrix2[ i ] ) ;   // was 0
		}
  */

}

void loop() {
  // put your main code here, to run repeatedly:
  // delay(10); // this speeds up the simulation
  if (Serial.available()) Serial.print((char)Serial.read()) ;
  delay(10) ;
}
ALU ZCON PC BUS - Sig 31-24 Sig 23-16 Sig 15-8 Sig 7-0
RegA RegB RegC RegD MAR INS SP ALU
regA (dec)
8 bit processor emulation à la James Bates