让Arduino函数在switch case中循环

时间:2017-03-21 21:07:10

标签: arduino

我正在尝试让函数flash()重复,但是当clickevent()再次出现并且案例0变为活动时它会停止。

我认为我的错误是案例0没有变得活跃,因为它可能会停留在案例1上?我可以让它开始使用while()语句或do while()语句,但是我无法退出循环,任何帮助都将非常感激。

// ======== change the lighting mode setting between flash and solid with a single click of the button ===========
int ModeSetting = 0;
void clickEvent()
{
    Serial.println("Click Occured");
    ModeSetting++;
    if (ModeSetting > 1)
        ModeSetting = 0;
    ChangeMode(ModeSetting);
}

void ChangeMode(int i)
{
    switch (i)
    {
    case 0:
        strip.setBrightness(255);
        Serial.println("MODE = SOLID COLOUR"); // SOLID LIGHT;
        break;
    case 1:
        flash(); // THE FUNCTION THAT NEEDS TO LOOP pls help

        break;
    }
}

int flashstate = LOW;
unsigned long PrevFlashMillis = 0;
const long flashinterval = 1000;
void flash()
{
    unsigned long currentFlashMillis = millis();
    if (currentFlashMillis - PrevFlashMillis >= flashinterval)
    {
        // save the last time you blinked the LED
        PrevFlashMillis = currentFlashMillis;
        // if the LED is off turn it on and vice-versa:
        if (flashstate == LOW)
        {
            strip.setBrightness(255);
            Serial.println("FLASH ON");
            flashstate == HIGH;
        }
        else
        {
            strip.setBrightness(0);
            Serial.println("FLASH OFF");
            flashstate == LOW;
        }
    }
}

0 个答案:

没有答案