Arduino Heart LED for beginners

Are you making the "with button" or "without button" version?

I think interruptibleDelay() is a clever way to run blocking code without missing a button press.

Using the "with button" LED configuration in Post #8, it seems this should be the "layers" (top, down)

  const int layer1[] = {8, 2};
  const int layer2[] = {7, 9, 3};
  const int layer3[] = {6, 4};
  const int layer4[] = {5};

or this (bottom, up)

  const int layer1[] = {5};
  const int layer2[] = {6, 4};
  const int layer3[] = {7, 9, 3};
  const int layer4[] = {8, 2};

I like "random" animations...

void runRandom() {
  int r = random(8); // eight LEDs
  digitalWrite(pins[r], HIGH);
  interruptibleDelay(ANIMATION_DELAY);
  digitalWrite(pins[r], LOW);
  if (checkButtonPressed()) {
    advanceMode();
  }
}

Click for Wokwi.com diagram.json tab
{
  "version": 1,
  "author": "foreignpigdog x",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": -4.8, "left": -0.5, "attrs": {} },
    {
      "type": "wokwi-led",
      "id": "led1",
      "top": -272.4,
      "left": 61.8,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r1",
      "top": -43.2,
      "left": 18.65,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r2",
      "top": -43.2,
      "left": 28.25,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r3",
      "top": -43.2,
      "left": 37.85,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r4",
      "top": -43.2,
      "left": 47.45,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r5",
      "top": -43.2,
      "left": 57.05,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r6",
      "top": -43.2,
      "left": 66.65,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r7",
      "top": -43.2,
      "left": 76.25,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r8",
      "top": -43.2,
      "left": 85.85,
      "rotate": 90,
      "attrs": { "value": "333" }
    },
    {
      "type": "wokwi-led",
      "id": "led2",
      "top": -330,
      "left": 33,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led3",
      "top": -330,
      "left": 90.6,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led4",
      "top": -272.4,
      "left": 4.2,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led5",
      "top": -272.4,
      "left": 119.4,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led6",
      "top": -214.8,
      "left": 33,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led7",
      "top": -214.8,
      "left": 90.6,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led8",
      "top": -157.2,
      "left": 61.8,
      "attrs": { "color": "yellow", "flip": "1" }
    },
    { "type": "wokwi-vcc", "id": "vcc1", "top": -85.64, "left": -9.6, "attrs": {} },
    { "type": "wokwi-gnd", "id": "gnd1", "top": 19.2, "left": -96.6, "attrs": {} },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": -51.4,
      "left": -86.4,
      "attrs": { "color": "green", "xray": "1" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r9",
      "top": 4.25,
      "left": -78.2,
      "rotate": 180,
      "attrs": { "value": "10000" }
    },
    {
      "type": "wokwi-text",
      "id": "text1",
      "top": -316.8,
      "left": 105.6,
      "attrs": { "text": "2" }
    },
    {
      "type": "wokwi-text",
      "id": "text2",
      "top": -259.2,
      "left": 134.4,
      "attrs": { "text": "3" }
    },
    {
      "type": "wokwi-text",
      "id": "text3",
      "top": -201.6,
      "left": 105.6,
      "attrs": { "text": "4" }
    },
    { "type": "wokwi-text", "id": "text4", "top": -144, "left": 76.8, "attrs": { "text": "5" } },
    { "type": "wokwi-text", "id": "text5", "top": -201.6, "left": 48, "attrs": { "text": "6" } },
    { "type": "wokwi-text", "id": "text6", "top": -259.2, "left": 19.2, "attrs": { "text": "7" } },
    { "type": "wokwi-text", "id": "text7", "top": -316.8, "left": 48, "attrs": { "text": "8" } },
    { "type": "wokwi-text", "id": "text8", "top": -259.2, "left": 76.8, "attrs": { "text": "9" } },
    {
      "type": "wokwi-text",
      "id": "text9",
      "top": -76.8,
      "left": -153.6,
      "attrs": { "text": "Press to change\nanimation" }
    }
  ],
  "connections": [
    [ "nano:9", "r1:2", "green", [ "v0" ] ],
    [ "nano:8", "r2:2", "green", [ "v0" ] ],
    [ "nano:7", "r3:2", "green", [ "v0" ] ],
    [ "nano:6", "r4:2", "green", [ "v0" ] ],
    [ "nano:5", "r5:2", "green", [ "v0" ] ],
    [ "nano:4", "r6:2", "green", [ "v0" ] ],
    [ "nano:3", "r7:2", "green", [ "v0" ] ],
    [ "nano:2", "r8:2", "green", [ "v0" ] ],
    [ "nano:GND.2", "led5:C", "black", [ "v-86.4", "h28.3", "v-134.4", "h-8.7" ] ],
    [ "nano:GND.2", "led7:C", "black", [ "v-86.4", "h28.3", "v-76.8", "h-37.5" ] ],
    [ "nano:GND.2", "led6:C", "black", [ "v-86.4", "h28.3", "v-76.8", "h-95.1" ] ],
    [ "nano:GND.2", "led8:C", "black", [ "v-86.4", "h28.3", "v-19.2", "h-66.3" ] ],
    [ "nano:GND.2", "led1:C", "black", [ "v-86.4", "h28.3", "v-134.4", "h-66.3" ] ],
    [ "nano:GND.2", "led4:C", "black", [ "v-86.4", "h28.3", "v-134.4", "h-123.9" ] ],
    [ "nano:GND.2", "led3:C", "black", [ "v-86.4", "h28.3", "v-192", "h-37.5" ] ],
    [ "nano:GND.2", "led2:C", "black", [ "v-86.4", "h28.3", "v-192", "h-95.1" ] ],
    [ "vcc1:VCC", "nano:5V.2", "red", [ "v0" ] ],
    [ "r8:1", "led3:A", "#8f4814", [ "v-19.2", "h-105.6", "v-182.4", "h96" ] ],
    [ "r7:1", "led5:A", "orange", [ "h0", "v-19.2", "h-96", "v-124.8", "h115.2" ] ],
    [ "r6:1", "led7:A", "gold", [ "h0", "v-19.2", "h-86.4", "v-67.2", "h105.6" ] ],
    [ "r5:1", "led8:A", "green", [ "h0", "v-19.2", "h-76.8", "v-9.6", "h57.6" ] ],
    [ "r4:1", "led6:A", "blue", [ "h0", "v-19.2", "h-67.2", "v-67.2", "h28.8" ] ],
    [ "r3:1", "led4:A", "violet", [ "h0", "v-19.2", "h-57.6", "v-124.8", "h9.6" ] ],
    [ "r2:1", "led2:A", "yellow", [ "v-19.2", "h-48", "v-182.4", "h38.4" ] ],
    [ "r1:1", "led1:A", "cyan", [ "h0", "v-19.2", "h-38.4", "v-124.8", "h67.2" ] ],
    [ "nano:12", "btn1:2.r", "green", [ "v0" ] ],
    [ "vcc1:VCC", "btn1:1.r", "red", [ "v0" ] ],
    [ "btn1:2.r", "r9:1", "green", [ "h9.8", "v29" ] ],
    [ "gnd1:GND", "r9:2", "black", [ "v0" ] ]
  ],
  "dependencies": {}
}
1 Like