TheTNR
Published © CC BY-SA

Heart Attack with LED

We tried to make a project called "Heart Attack with LED". This is different. Because it will be a gift for your lover.

IntermediateFull instructions provided2,732
Heart Attack with LED

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×4
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×4
3D Printable Parts
×6

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Circuit

Code

Arduino Nano Code

Arduino
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

#define NEO_PIN 6           // Neopixel pin
#define GND_PIN 9           // Signal pin used as ground
#define GND_PIN2 1          // Signal pin used as ground
#define SPEED_PIN A4       // Analog (ADC) input pin to read value of speed potentiometer
#define COLOR_PIN A5       // Analog (ADC) input pin to read value of color potentiometer
#define MAX_BRIGHTNESS 50   // Maximum Neopixel brightness
#define UP_STEPS 5          // Increasing brightness steps out of the total number of steps (smaller than half total => fast rise, slow decay)
#define TOTAL_STEPS 40      // Total number of increasing/deeasing steps
#define SPEED_DIVIDER 30    // Used to divide the value of the speed ADC readout to calculate iteration delay

const int heart[] = {       // Heart bitmap
  0, 1, 1, 0, 1, 1, 0, 0,
  1, 1, 1, 1, 1, 1, 1, 0,
  1, 1, 1, 1, 1, 1, 1, 0,
  1, 1, 1, 1, 1, 1, 1, 0,
  0, 1, 1, 1, 1, 1, 0, 0,
  0, 0, 1, 1, 1, 0, 0, 0,
  0, 0, 0, 1, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0
};

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(4, 4, 2, 2, NEO_PIN,
  NEO_TILE_TOP   + NEO_TILE_LEFT   + NEO_TILE_COLUMNS   + NEO_TILE_ZIGZAG +
  NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
  NEO_GRB + NEO_KHZ800);

void setup() {
  matrix.begin();
  matrix.setBrightness(40);

  pinMode(GND_PIN, OUTPUT);
  digitalWrite(GND_PIN, LOW); // Lazy ground
  pinMode(GND_PIN2, OUTPUT);
  digitalWrite(GND_PIN2, LOW); // Lazy ground
  pinMode(SPEED_PIN, INPUT);
  pinMode(COLOR_PIN, INPUT);
}

void loop() {
  int i, j;
  int brightness;
  int color;
  
  for (i = 0; i < TOTAL_STEPS; i++) {
    if (i < UP_STEPS)
      brightness = MAX_BRIGHTNESS * i / UP_STEPS;
    else
      brightness = MAX_BRIGHTNESS * (TOTAL_STEPS - i - 1) / (TOTAL_STEPS - UP_STEPS);
    matrix.setBrightness(brightness);
    color = analogRead(COLOR_PIN) / 4;
    
    for (j = 0; j < 64; j++) {
      
      matrix.drawPixel(j / 8, j % 8, Wheel(color)*heart[j]);
      
    }
    
    
    matrix.show();
    delay(analogRead(SPEED_PIN) / SPEED_DIVIDER);
  }
}

uint32_t Wheel(byte WheelPos) { // Courtesy of multiple Adafruit examples
  if (WheelPos < 85) {
    return matrix.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return matrix.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
    WheelPos -= 170;
    return matrix.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Credits

TheTNR
5 projects • 156 followers
A teacher at high school. I am an electronics teacher.

Comments