当前位置: 首页>>代码示例>>C++>>正文


C++ SimpleTimer::toggle方法代码示例

本文整理汇总了C++中SimpleTimer::toggle方法的典型用法代码示例。如果您正苦于以下问题:C++ SimpleTimer::toggle方法的具体用法?C++ SimpleTimer::toggle怎么用?C++ SimpleTimer::toggle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleTimer的用法示例。


在下文中一共展示了SimpleTimer::toggle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CenterSmartUpdate

inline void CenterSmartUpdate()
{
    center = analogRead(CENTER_SENSOR);

    if (centerTimeoutCount)
        centerTimeoutCount += 1;

    if (!centerOldHigh && (center > centerSchmittHigh.Value)) // On switch-to-high
    {
        centerOldHigh = true; // Switch current center state to high

        if((intersectionSignalRecent + 1) == INTERSECTION_COUNT_ORIGIN) // If the start/stop signal is encountered, toggle clock.
        // This is done on when it switches high (instead of waiting for timeout) to save a bit of clock-time.
        {
            lapTimer.toggle(0);
            if (!lapTimer.isEnabled(0))
            {
               // Stop motors before entering menu
                MotorSpeed(LEFT_MOTOR, 0);
                MotorSpeed(RIGHT_MOTOR, 0);

                Clear();
                Cursor(TOP, 0);
                Print("Finish!");
                currentState = menu;
                delay(800);
                return;
            }

        }

        switch(intersectionTurnFlag)
        {
            case INTERSECTION_COUNT_LEFT: // First intersection after left signal
            currentState = turnLeft;
            break;
            case INTERSECTION_COUNT_RIGHT: // First intersection after right signal
            currentState = turnRight;
            break;
            default: // Else
            currentState = moveStraight;
            intersectionSignalRecent += 1;
            break;
        }

        centerTimeoutCount = 0; // Stop timeout counter
        intersectionTurnFlag = 0; // Reset flag
    }
    else if (centerOldHigh && (center < centerSchmittLow.Value)) // On switch-to-low
    {
        centerOldHigh = false; // Swtich current center state to low
        centerTimeoutCount = 1; // Start timeout counter
    }

    if (centerTimeoutCount >= (centerTimeoutLimit.Value * 2)) // Timeout
    {
        if (intersectionTurnFlag < intersectionSignalRecent) // Do not let false signals effect the flag
            intersectionTurnFlag = intersectionSignalRecent; // Set flag

        intersectionSignalRecent = 0; // Reset signal counter
        centerTimeoutCount = 0; // Stop timeout counter
    }
}
开发者ID:johndharvey,项目名称:Robert-roving-robot,代码行数:63,代码来源:Wire+following+PID+control.cpp


注:本文中的SimpleTimer::toggle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。