没有 SD 卡的 Arduino 音频播放不起作用?

Arduino audio playback without SD card not working?

我想创建一个主要播放 2 个音频的电路,一个在通电时播放,另一个通过按下按钮播放。我想在没有 SD 卡的情况下创建它。使用的库是PCM。 这是代码示例。

#include <PCM.h>

const unsigned char sample[] PROGMEM = {
  0,6,14,22,30,38,46,54,60,68,74,82,90,98,106,114,112,
  };

void setup()
{
    startPlayback(sample, sizeof(sample));
}

void loop()
{
 
}

如果有人知道如何使用按钮在 arduino 中播放音频(没有 sd 卡) 帮帮我...

已解决:通过添加 INPUT_PULLUP

const unsigned char sample2[] PROGMEM = {
    100,96,84,72,60,58,46,34,20,18,4,12,20,38,46,54,62,
};

int inPin = 7;
void setup()
{
    pinMode(inPin, INPUT_PULLUP);
}

int lastPin = HIGH;  // HIGH means not pressed for Pullup Inputs
void loop()
{
    int pin = digitalRead(inPin);

    if (pin == lastPin)
        return;

    if (pin == HIGH) {
       startPlayback(sample1, sizeof(sample1));
    } else {
       startPlayback(sample2, sizeof(sample2));
    }

    lastPin = pin;
}