Wür­feln LED-Matrix Ardui­no R4 WiFi

Arrays als Byte-Array

# include "Arduino_LED_Matrix.h"

int TASTER = 7;

/*
  Minimum und Maximum der Zufallszahlen
  ermittelde Zahl wird immer nach unten gerundet
  -> maximaler Wert muss 7 sein
*/
int Minimum = 1;
int Maximum = 7;

// Name der Matrix
ArduinoLEDMatrix Matrix;

// Start-Button 
byte StartButton[8][12] = 
{
  { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 },
  { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
  { 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0 },
  { 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0 },
  { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
  { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }
};

byte eins[8][12] = 
{
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};

byte zwei[8][12] = 
{
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0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
  { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
  { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }
};

byte sechs[8][12] = {
  { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 },
  { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 },
  { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 }
};

void setup() 
{
  Matrix.begin();

  // Zufallsgenerator starten
  randomSeed(A0);

  pinMode(TASTER, INPUT_PULLUP);

  // Start-Button anzeigen
  Matrix.renderBitmap(StartButton, 8, 12);
}

void loop() 
{
  // Zustand des Tasters lesen
  int TasterLesen = digitalRead(TASTER);

  if (TasterLesen == LOW) 
  {
    delay(200);

    // Würfeleffekt
    for (int i = 0; i < 5; i++) 
    {
      Wuerfeln();
      delay(200);
    }
  }
}

void Wuerfeln() 
{
  // Zufallszahl ermitteln
  int Zahl = random(Minimum, Maximum);

  // Abfrage der gewürfelten Zahl
  switch (Zahl) 
  {
    case 1:
      Matrix.renderBitmap(eins, 8, 12);
      break;

    case 2:
      Matrix.renderBitmap(zwei, 8, 12);
      break;

    case 3:
      Matrix.renderBitmap(drei, 8, 12);
      break;

    case 4:
      Matrix.renderBitmap(vier, 8, 12);
      break;

    case 5:
      Matrix.renderBitmap(vier, 8, 12);
      break;

    case 6:
      Matrix.renderBitmap(sechs, 8, 12);
      break;
  }
}

Arrays mit Matrix-Edi­tor erstellt

# include "Arduino_LED_Matrix.h"

int TASTER = 7;

/*
  Minimum und Maximum der Zufallszahlen
  ermittelde Zahl wird immer nach unten gerundet
  -> maximaler Wert muss 7 sein
*/
int Minimum = 1;
int Maximum = 7;

// Name der Matrix
ArduinoLEDMatrix Matrix;

// Array Start-Button
const unsigned long StartButton[] =
{
  0x6009010,
  0x82642641,
  0x8090060,
};

const unsigned long eins[] =
{
  0x0,
  0x600600,
  0x0
};

const unsigned long zwei[] =
{
  0x300300,
  0x0,
  0xc00c00
};

const unsigned long drei[] =
{
  0x300300,
  0x600600,
  0xc00c00,
};

const unsigned long vier[] =
{
  0xc03c0300,
  0x0,
  0xc03c03
};

const unsigned long fuenf[] =
{
  0xc03c0300,
  0x600600,
  0xc03c03
};

const unsigned long sechs[] =
{
  0xc63c6300,
  0x0,
  0xc63c63
};

void setup()
{
  Matrix.begin();

  // Zufallsgenerator starten
  randomSeed(A0);

  pinMode(TASTER, INPUT_PULLUP);
  Matrix.loadFrame(StartButton);
}

void loop()
{
  int TasterLesen = digitalRead(TASTER);
  if (TasterLesen == LOW)
  {
    delay(200);

    // Würfeleffekt
    for (int i = 0; i < 5; i++)
    {
      Wuerfeln();
      delay(200);
    }
  }
}

void Wuerfeln()
{
  int Zahl = random(Minimum, Maximum);
  switch (Zahl)
  {
    case 1:
      Matrix.loadFrame(eins);
      break;
    case 2:
      Matrix.loadFrame(zwei);
      break;
    case 3:
      Matrix.loadFrame(drei);
      break;
    case 4:
      Matrix.loadFrame(vier);
      break;
    case 5:
      Matrix.loadFrame(fuenf);
      break;
    case 6:
      Matrix.loadFrame(sechs);
      break;
  }
}

Letzte Aktualisierung: 25. Jul 2023 @ 21:39