按键修改流水灯的花型,一共四种花型。



cpp展开代码    while (1)
    {
        PinIN();
        I2C_IODect(); /*按键检测处理 */
        delay_ms(20);
        time++;
        if (time > 6)
        {
            time = 0;
            if (mode == 0)
            {
                index++;
                if (index > 7)
                {
                    index = 0;
                }
                PinOUT(0, 1); /* 指定0号管脚输出为0 */
                PinOUT(1, 1); /* 指定1号管脚输出为0 */
                PinOUT(2, 1); /* 指定0号管脚输出为0 */
                PinOUT(3, 1); /* 指定1号管脚输出为0 */
                PinOUT(4, 1); /* 指定0号管脚输出为0 */
                PinOUT(5, 1); /* 指定1号管脚输出为0 */
                PinOUT(6, 1); /* 指定0号管脚输出为0 */
                PinOUT(7, 1); /* 指定1号管脚输出为0 */
                PinOUT(index, 0); /* 指定0号管脚输出为0 */
            }
            else if (mode == 1)
            {
                if (index == 0)
                {
                    index = 7;
                }
                else
                {
                    index--;
                }
                PinOUT(0, 1); /* 指定0号管脚输出为0 */
                PinOUT(1, 1); /* 指定1号管脚输出为0 */
                PinOUT(2, 1); /* 指定0号管脚输出为0 */
                PinOUT(3, 1); /* 指定1号管脚输出为0 */
                PinOUT(4, 1); /* 指定0号管脚输出为0 */
                PinOUT(5, 1); /* 指定1号管脚输出为0 */
                PinOUT(6, 1); /* 指定0号管脚输出为0 */
                PinOUT(7, 1); /* 指定1号管脚输出为0 */
                PinOUT(index, 0); /* 指定0号管脚输出为0 */
            }
            else if (mode == 2)
            {
                index++;
                if (index > 15)
                {
                    index = 0;
                }
                PinOUT(0, 1); /* 指定0号管脚输出为0 */
                PinOUT(1, 1); /* 指定1号管脚输出为0 */
                PinOUT(2, 1); /* 指定0号管脚输出为0 */
                PinOUT(3, 1); /* 指定1号管脚输出为0 */
                PinOUT(4, 1); /* 指定0号管脚输出为0 */
                PinOUT(5, 1); /* 指定1号管脚输出为0 */
                PinOUT(6, 1); /* 指定0号管脚输出为0 */
                PinOUT(7, 1); /* 指定1号管脚输出为0 */
                if (index < 8)
                {
                    PinOUT(index, 0); /* 指定0号管脚输出为0 */
                }
                else
                {
                    PinOUT(7 - (index - 8), 0); /* 指定0号管脚输出为0 */
                }
            }
            else if (mode == 3)
            {
                index++;
                if (index > 3)
                {
                    index = 0;
                }
                PinOUT(0, 1); /* 指定0号管脚输出为0 */
                PinOUT(1, 1); /* 指定1号管脚输出为0 */
                PinOUT(2, 1); /* 指定0号管脚输出为0 */
                PinOUT(3, 1); /* 指定1号管脚输出为0 */
                PinOUT(4, 1); /* 指定0号管脚输出为0 */
                PinOUT(5, 1); /* 指定1号管脚输出为0 */
                PinOUT(6, 1); /* 指定0号管脚输出为0 */
                PinOUT(7, 1); /* 指定1号管脚输出为0 */
                if (index == 0)
                {
                    PinOUT(0, 0); /* 指定0号管脚输出为0 */
                    PinOUT(7, 0); /* 指定1号管脚输出为0 */
                }
                else if (index == 1)
                {
                    PinOUT(1, 0); /* 指定0号管脚输出为0 */
                    PinOUT(6, 0); /* 指定1号管脚输出为0 */
                }
                else if (index == 2)
                {
                    PinOUT(2, 0); /* 指定0号管脚输出为0 */
                    PinOUT(5, 0); /* 指定1号管脚输出为0 */
                }
                else if (index == 3)
                {
                    PinOUT(3, 0); /* 指定0号管脚输出为0 */
                    PinOUT(4, 0); /* 指定1号管脚输出为0 */
                }
            }
        }
    }
}
cpp展开代码https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2


本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!