Example Code for Arduino-Beating Heart

Last revision 2026/01/12

The article delves into the ATmega32U4 Beating Heart LED Matrix Module, offering sample code and guidance on hardware and software setup. It explores the module's functionalities like USB interface, touch button control, and vibration sensor, providing makers and hobbyists with a comprehensive guide to creating dynamic electronic heart patterns.

Hardware Preparation

Software Preparation

Sample Code

/*
# This sample code is for testing the Throbbing Heart. After uploaded the code, you will see a beating heart.
 # Platform : Arduino Leonardo
 # Editor   : YouYou
 # Date     : 2014.05.19
 # Ver      : 1.0
 # Product  : Throbbing Heart
 # SKU      : DFR0286
*/

const byte row[8] = {9, 8, 4, A3, 3, 10, 11, 6};
const byte col[8] = {2, 7, A5, 5, 13, A4, 12, A2};
const unsigned int interval = 500;
byte picture[16][8] PROGMEM =
{
    {0,0,0,0,0,0,0,0},//pattern 0
    {0,1,1,0,0,1,1,0},
    {1,1,1,1,1,1,1,1},
    {1,1,1,1,1,1,1,1},
    {1,1,1,1,1,1,1,1},
    {0,1,1,1,1,1,1,0},
    {0,0,1,1,1,1,0,0},
    {0,0,0,1,1,0,0,0},

    {0,0,0,0,0,0,0,0},//pattern 1
    {0,0,0,0,0,0,0,0},
    {0,0,1,0,0,1,0,0},
    {0,1,1,1,1,1,1,0},
    {0,1,1,1,1,1,1,0},
    {0,0,1,1,1,1,0,0},
    {0,0,0,1,1,0,0,0},
    {0,0,0,0,0,0,0,0},
};
void LED_Init(void)
{
    for (byte thisPin = 0; thisPin < 8; thisPin++)
    {
        pinMode(col[thisPin], OUTPUT);
        pinMode(row[thisPin], OUTPUT);
        digitalWrite(row[thisPin], LOW);
        digitalWrite(col[thisPin], HIGH);
    }
}
void Draw_Pic(const byte *pict PROGMEM,byte number)
{
    for (byte thisRow = 0; thisRow < 8; thisRow++)
    {
        pinMode(row[thisRow], OUTPUT);
        digitalWrite(row[thisRow], HIGH);
        for (byte thisCol = 0; thisCol < 8; thisCol++)
        {
          byte thisPixel= pgm_read_byte(pict+8*(thisRow+number*8)+thisCol);
             pinMode(col[thisCol], OUTPUT);
             digitalWrite(col[thisCol], !thisPixel);
             if (thisPixel == HIGH)
             {
                delayMicroseconds(80);
                digitalWrite(col[thisCol], HIGH);
             }
        }
        digitalWrite(row[thisRow], LOW);
    }
}
void setup(void)
{
  LED_Init();
}
void loop(void)
{
  static unsigned long time=millis();
  static byte picnum = 0x00;
  Draw_Pic((byte *)picture,picnum);
  if(millis()-time>=interval)
  {
    time=millis();
    picnum ^= 0x01;
  }
}

Result

When uploaded to it, you will see a beating heart.

Additional Information

Function Overview

  • USB Interface

Beating_Heart_USB_Port

After plugging with the USB cable, it will automatically charge the battery (red light), automatically stop when charged done (green light), while lit LED dot matrix. At this time, you can also use Mind+ or Arduino IDE to program,for making your own personality patterns!

  • Touch Button

Beating_Heart_Button

Touch once to change the speed of the heartbeat. Press and hold to flash quickly from small to large.

  • Power Switch

Beating_Heart_Switch

Dial it up, the power is turned on. Dial it down, the power is turned off.

  • Vibration Sensor

Beating_Heart_Vibration_Sensor

When shake the electronic heart intensely, the built-in vibration sensor will response and change the pattern from buttom to top.

Other Function Code

Was this article helpful?

TOP