I do not understand "front and back." Can you draw a picture and post it here?
Here is a small simulation of your code (press the green play button at the top of the simulation).
Use these files in WOKWI.COM
sketch.ino
// https://forum.arduino.cc/t/max7219-code-help/1106250/
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define DATA_PIN 11
#define CLK_PIN 13
#define CS_PIN 8
#define BUTTON_PIN 7
int currentBUTTON;
int lastBUTTON;
bool toggleSTATE;
// Hardware SPI connection
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
byte heart[] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18};
byte face1[] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};
byte face2[] = {0x00, 0x24, 0x24, 0x24, 0x00, 0x42, 0x3C, 0x00};
byte arrow[] = {0x18, 0x0C, 0x06, 0xFF, 0xFF, 0x06, 0x0C, 0x18};
void setup() {
Serial.begin(115200);
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, 0);
mx.clear();
pinMode(BUTTON_PIN, INPUT);
currentBUTTON = digitalRead(BUTTON_PIN);
}
void loop() {
lastBUTTON = currentBUTTON;
currentBUTTON = digitalRead(BUTTON_PIN);
delay(50);
// watchButtonState(); // watch the button state in the serial monitor
if ((lastBUTTON == 1) && (currentBUTTON == 0)) // button is PRESSED and state has CHANGED H to L
{
if (toggleSTATE == LOW) // if the toggle state was LOW...
{
toggleSTATE = HIGH; // ... set the toggle state HIGH
drawShape1(); // ... and draw shape 1
}
else
{
toggleSTATE = LOW; // otherwise set the toggle state LOW
drawShape2(); // ... and draw shape 2
}
}
}
void drawShape1()
{
for (int i = 0; i <= 7; i++) {
mx.setRow(0, 0, i, face1[i]);
}
}
void drawShape2()
{
for (int i = 0; i <= 7; i++) {
mx.setRow(0, 0, i, heart[i]);
}
}
void drawShape3()
{
for (int i = 0; i <= 7; i++) {
mx.setRow(2, 2, i, face2[i]);
}
}
void drawShape4()
{
for (int i = 0; i <= 7; i++) {
mx.setRow(3, 3, i, arrow[i]);
}
}
void watchButtonState() {
Serial.print(currentBUTTON);
Serial.print(" ");
delay(100); // remove this... only here to see button presses
}
diagram.json
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": -47.4, "left": -29.4, "attrs": {} },
{
"type": "wokwi-max7219-matrix",
"id": "matrix1",
"top": -124.2,
"left": -34.59,
"attrs": { "chain": "1" }
},
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": -118.6,
"left": 182.4,
"attrs": { "color": "green" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": 110.4,
"left": 229.85,
"rotate": 90,
"attrs": { "value": "1000" }
}
],
"connections": [
[ "matrix1:CS", "uno:8", "green", [ "h38.4", "v0", "h18.8" ] ],
[ "btn1:2.r", "r1:1", "green", [ "h9.8", "v153.8" ] ],
[ "r1:2", "uno:GND.3", "black", [ "h-0.16", "v18", "h-119.04" ] ],
[ "uno:5V", "matrix1:V+", "red", [ "v0" ] ],
[ "uno:13", "matrix1:CLK", "green", [ "v0" ] ],
[ "uno:11", "matrix1:DIN", "green", [ "v0" ] ],
[ "uno:7", "btn1:2.l", "green", [ "v0" ] ],
[ "uno:5V", "btn1:1.l", "red", [ "v0" ] ],
[ "uno:GND.1", "matrix1:GND", "black", [ "v0" ] ]
],
"dependencies": {}
}
