首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用NeoPixels实现Arduino函数的不正确循环

用NeoPixels实现Arduino函数的不正确循环
EN

Stack Overflow用户
提问于 2015-09-24 18:40:43
回答 1查看 75关注 0票数 0

在我工作的地方,我正在用Arduino + NeoPixels来点亮一个万圣节的标志。我的两个功能之一(缓慢,传播,红色辉光)工作良好。另一个--心跳减慢--从来没有慢下来,似乎陷入了一个无限的循环。

以下是完整的相关代码:

代码语言:javascript
复制
void loop() {
    // HeartBeat Test
   for(int bpm=60;bpm >= 0;bpm=bpm-3) {
       systolicUp(bpm);
       systolicDown(bpm);
       diastolicUp(bpm);
       diastolicDown(bpm);
       restBeat(bpm);
   }
}


void systolicUp(int i) {
    uint16_t beatSeconds, firstPulse, firstIncrement, j, k;
    beatSeconds =  60000/i;
    firstPulse = beatSeconds * 0.6;
    firstIncrement = firstPulse/170;
    for(j=0; j <= 255; j=j+3) {
        uint32_t redShade = strip.Color(j, 0, 0);
        for (k=0; k<strip.numPixels(); k++) {
            strip.setPixelColor(k, redShade);
        }
        strip.show();
        delay(firstIncrement);
    }
}

void systolicDown(int i) {
    uint16_t beatSeconds, firstPulse, firstIncrement, j, k;
    beatSeconds =  60000/i;
    firstPulse = beatSeconds * 0.6;
    firstIncrement = firstPulse/170;
    for(j=255; j >= 0; j=j-3) {
        uint32_t redShade = strip.Color(j, 0, 0);
        for (k=0; k<strip.numPixels(); k++) {
            strip.setPixelColor(k, redShade);
        }
        strip.show();
        delay(firstIncrement);
    }
}

void diastolicUp(int i) {
    uint16_t beatSeconds, secondPulse, secondIncrement, j, k;
    beatSeconds =  60000/i;
    secondPulse = beatSeconds * 0.3;
    secondIncrement = secondPulse/170;
    for(j=0; j <= 255; j=j+3) {
        uint32_t redShade = strip.Color(j, 0, 0);
        for (k=0; k<strip.numPixels(); k++) {
            strip.setPixelColor(k, redShade);
        }
        strip.show();
        delay(secondIncrement);
    }
}

void diastolicDown(int i) {
    beatSeconds =  60000/i;
    uint16_t beatSeconds, secondPulse, secondIncrement, j, k;
    secondPulse = beatSeconds * 0.3;
    secondIncrement = secondPulse/170;
    for(j=255; j >= 0; j=j-3) {
        uint32_t redShade = strip.Color(j, 0, 0);
        for (k=0; k<strip.numPixels(); k++) {
            strip.setPixelColor(k, redShade);
        }
        strip.show();
        delay(secondIncrement);
    }
}

void restBeat(int i) {
    uint16_t beatSeconds, rest, g;
    beatSeconds =  60000/i;
    rest = beatSeconds * 0.1;
    for (g=0; g<strip.numPixels(); g++) {
        strip.setPixelColor(g, 0, 0, 0);
    }
    strip.show();
    delay(rest);
}

从数学上讲,我应该每分钟交一定的拍数,计算出每拍秒数,光脉冲超过60%,脉冲再超过30%,然后保持10%的静音。这应该发生20次,每个节拍逐渐变慢,直到完全停止。

相反,我正以每秒一次的速度稳定地闪烁。

我确信它最终会被我完全忽略,或者在NeoPixel文档中被忽略了。但是,由于我不是忽略了它,就是完全错过了它,我将感激你的帮助。:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-24 18:55:18

在这里,您试图在声明void diastolicDown(int i) { beatSeconds = 60000/i; uint16_t beatSeconds, secondPulse, secondIncrement, j, k;之前将一个值赋值给beatSeconds

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32768618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档